I managed to use then ansible community community.general.proxmox
to make a role that creates a lxc machine on my proxmox cluster. The problem is that it fails to wait for the machine to start. It says that there is no vm with the name whatever-name
, but If I run it a second time it fully succeeds. Note that I'm using dhcp to assign the IP, and that after the machine gets an ip from my dhcp server it is reachable by name, because my dhcp also acts as DNS server, and I can reach all my lxc machines by hostname without problem.
Here is the role that creates the machine, and then fails at the last step:
---
- name: bla
debug:
msg: "{{ api_host }}"
- name: Create new container with minimal options defining network interface with DHCP
# delegate_to: localhost
connection: local
community.general.proxmox:
api_host: "{{ api_host }}" # The proxmox instance
api_user: root@pam
api_password: "{{ proxmox_api_key }}" #Make sure to read from a vault
node: "{{ proxmox_node }}"
cores: 1
disk: "{{ disk_size }}" # GB
memory: "{{ memory }}"
nameserver: 192.168.0.110
password: "{{ password }}"
hostname: "{{ container_name }}"
unprivileged: no
pubkey: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
storage: "{{ container_storage }}"
ostemplate: "{{ container_os_template }}"
netif: '{"net0":"name=eth0,gw=192.168.0.1,ip=dhcp,bridge=vmbr0"}'
features:
- nesting=1
description: created with ansible
state: present
- name: Start the container
# delegate_to: localhost
connection: local
community.general.proxmox:
api_host: "{{ api_host }}" # The proxmox instance
api_user: root@pam
api_password: "{{ proxmox_api_key }}" #Make sure to read from a vault
node: "{{ proxmox_node }}"
hostname: "{{ container_name }}"
state: started
unprivileged: no
- name: Wait for the container to start
connection: local
wait_for:
host: "{{ container_name }}.home"
port: 22
sleep: 3
connect_timeout: 5
timeout: 60
How can I make this work in just one run?