Proxmox

Hi everyone,

As i am new to Ansible i still have a lot to learn.

I have been playing with Ansible and Proxmox for some time. I want to run Ansible within a Proxmox container without having to install SSH inside every container.
It’s possible to run commands inside a container using SSH on the Proxmox host. So far so good. I am able to run Ansible inside a container by modifying (prefixing) the ansible_python_interpreter variable.

Currently i need to hard code the container id inside the ansible_python_interpreter variable. Also i have to make sure the path on the host and the mounted shared folder have the same path. Else Ansible will try to run the wrong python file.

I would like to make this in a way i can specify the container id and the Proxmox host and have Ansible run commands inside the container.

Anyone any suggestions where to start? Should i make a new connection plugin? Or is there any other way to get the same result?

Regards,

Pim

Hi Pim , maybe this can work for you; you can run a command inside the container with something like that:

  • name: run command
    hosts: proxmox
    tasks:
  • name: Run command in container
    lxc_container:
    name: 133
    state: started
    container_command: service ssh restart

Thanks for the reply. This could run a command inside a container. But i would like to run a complete playbook inside a container.

Now i can set something like: ansible_connection=ssh ansible_python_interpreter=“pct exec 212 – python3” ansible_remote_tmp=/var/lib/lxc/212/rootfs/var/tmp/ (it requires python3 inside the container)

This kindda works. But it requires the container ID on 2 places inside the host connection settings. It also requires me to make a symlink inside the container so that the /var/lib/lxc/212/rootfs/var/tmp/ folder points to the correct tmp folder where the files where placed. I don’t mind the symlink. But i don’t like it to put it as a extra task in the playbook. I would like ansible to handle it for me.

Thanks,

Pim