--- - hosts: all tasks: - name: install lxc package: name: '{{item}}' state: present update_cache: yes with_items: - lxc - python3-lxc - name: Configuration de lxc copy: src: default.conf dest: /etc/lxc/default.conf - name: Creation d'un container rocky community.general.lxc_container: name: rocky-lxc template: download template_options: --dist rockylinux --release 9 --arch amd64 state: started container_command: | dnf check-update dnf install -y openssh-server python3 systemctl enable --now sshd - name: Creation d'un container debian community.general.lxc_container: name: debian-lxc template: download template_options: --dist debian --release bookworm --arch amd64 state: started container_command: | apt update apt install -y openssh-server python3 systemctl enable --now ssh - name: copie des clefs ssh copy: src: "~/.ssh/id_rsa.pub" dest: "{{item}}" mode: "0600" with_items: - /var/lib/lxc/debian-lxc/rootfs/root/.ssh/authorized_keys - /var/lib/lxc/rocky-lxc/rootfs/root/.ssh/authorized_keys - name: recuperation ip rocky shell: "lxc-info -iH rocky-lxc" register: ip_rocky - name: recuperation ip debian shell: "lxc-info -iH debian-lxc" register: ip_debian - name: inventaire remote_user: "jerome" become: no copy: content: "[containers]\n{{ip_rocky.stdout}}\n{{ip_debian.stdout}}" dest: "hosts" delegate_to: localhost - name: ssh-keyscan remote_user: "jerome" become: no shell: cmd: ssh-keyscan -H -f hosts >> ~/.ssh/known_hosts delegate_to: localhost