Open krepflap opened 6 years ago
Hi @krepflap. I had similar issues and I think it may be due to Hetzner's ubuntu image doing apt upgrade
on boot.
I tried to work around it like this:
https://github.com/m110/infrastructure-as-code/blob/master/packer/hcloud/base.json https://github.com/m110/infrastructure-as-code/blob/master/packer/scripts/python.sh
It did help with this issue, but it's far from elegant solution. :(
If all you need is to install python, you could consider setting cloudinit data in user_data
field. I tested in only with Terraform, but it should work as well with the packer build.
You could try:
#cloud-config
packages:
- python
are there any news on this issue? neither the shell solution nor the proposed cloudinit solution ("user_data": "#cloud-config\npackages:\n - python\n"
) work for me. So atm there is no way to start ubuntu servers with ansible provisioning...
@arosenhagen : I ended up doing it like this since I wanted to provision with ansible as well. In the playbook you call from packer:
[...]
tasks:
- name: Kill auto apt update
raw: pkill -9 apt
- name: Update apt
raw: apt-get -qq update
- name: Install python and sudo
raw: apt-get install -y -qq python sudo
Next task you can use normal ansible modules... Of course this is a nasty workaround, but waiting for the locks to clear while the Hetzner images were auto updating gave me way too much issues.
Don't forget in a next task to actually update the packages of course, since we killed that process, something like:
- name: Update all packages
apt:
name: "*"
state: latest
update_cache: no
autoremove: yes
I don't think this will work. In order to use ansible you already have to have python installed:
TASK [Gathering Facts] *********************************************************
fatal: [default]: FAILED! => {"changed": false, "module_stderr": "/bin/sh: 1: /usr/bin/python: not found\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 127}
So the only way is to actually use the shell provisioner (which actually fails with a timeout).
It works, you have to disable gather facts on the first play though. Here is the full code of the bootstrap play. After that you can do whatever, including gathering facts etc. Ansible can work with raw
module without python.
---
- name: Bootstrap server
hosts: all
gather_facts: no
tasks:
- name: Kill auto apt update
raw: pkill -9 apt
- name: Update apt
raw: apt-get -qq update
- name: Install python and sudo
raw: apt-get install -y -qq python sudo
- name: Update all packages
apt:
name: "*"
state: latest
update_cache: no
autoremove: yes
- name: Cleanup
command: apt-get clean
thx! that works out in the end ;-)
Thanks for this project.
Is it possible the shell provider isn't working?
The step
==> hcloud: Provisioning with shell script: ...
takes a long time.Packer definition:
I've just tried with ansible provisioner and that works (using paramiko).
Thanks!