Ansible + LXC: How to run commands on the Host System?


New LXC user and first post on the forum.

I’ve been testing LXC for a few days… and well… this is great. I’ve been searching for a tool like this and by luck on a podcast someone referred LXC.

I don’t know how a tool like LXC is not common knowledge.

My question. I’ve made some tests using Ansible using the community.general

ansible-galaxy collection install community.general -f

The problem that I’ve is that I’m able to run tasks on the containers but my knowledge of Ansible does not allow me to run tasks on the Host System on the same Ansible Playbook.

I’ve LXC installed on a VMWare VM, and I need to run this LXC commands on the Host System:

lxc config device add proxy myport80 proxy listen=tcp: connect=tcp: proxy_protocol=true
lxc config device add proxy myport443 proxy listen=tcp: connect=tcp: proxy_protocol=true

The hosts.yml Ansible Script is the following:

    ansible_connection: lxd
    ansible_user: root
    ansible_become: no
        ansible_lxd_remote: # this IP is the name of the remote lxd...

With this hosts.yml I’m able to target the LXC container “ubuntu22-0402”.

What I need to do on the same playbook is to target the “vmware” ( I don’t know if this is possible.

I know that this is an Ansible question, but I asked here because I think this is a specific question and someone who runs LXC with Ansible probably have needed to do something similar.

Maybe the only solution is to target “vmware” ( in another Playbook with another “hosts.yml”.

André Lopes.