1

I have a setup of ansible and different server for LXD. Can anyone provide me the plugin that can be used to do stuffs inside LXD container through ansible like installing nginx or removing default ubuntu user.

Lxd version: 4 (ubuntu 20.04 LTS) Ansible version: 5(ansible-core 2.12) --> ubuntu 20.04 LTS

My tasks>main.yml looks like this.

- name: dynamic-site-host
  add_host:
    name: "{{ item.container_name }}-host"
    ansible_host: "{{ ansible_host }}" 
    #ansible_connection: lxd
    ansible_ssh_extra_args: "{{ item.container_name }}"
    ansible_ssh_user: root
    ansible_python_interpreter: /usr/bin/python3
  with_items: "{{ container_params }}"

- name: set-dynamic-site-host-name
  delegate_to: "{{ item.container_name }}-host"
  set_fact:
    site_host_name: "{{ item.container_name }}-host"
  with_items: "{{ container_params }}"

- name: set-site-vars-dynamically
  delegate_to: "{{ site_host_name }}"
  set_fact:
    site_params: "{{ item }}"
  with_items: "{{ container_params }}"

- name: Remove the user 'ubuntu'
  delegate_to: "{{ site_host_name }}"
  user:
    name: ubuntu
    state: absent
    remove: yes

ansible.cfg

[defaults]

inventory= ./hosts
#connection_plugins = ./plugins/lxc_ssh/
ansible_host_key_checking= false

host file

[default]

hosting ansible_host=138.xxx.xxx.xx ansible_ssh_user=root
vidarlo
  • 6,654
  • 2
  • 18
  • 31
gzala
  • 21
  • 2
  • Requests for product, service, or learning material recommendations are off-topic because they attract low quality, opinionated and spam answers, and the answers become obsolete quickly. Instead, describe the business problem you are working on, the research you have done, and the steps taken so far to solve it. – djdomi Dec 31 '21 at 22:15

1 Answers1

0

You can run tasks in LXD containers through ssh as on normal hosts or your can use LXC container ansible module

AlexD
  • 8,747
  • 2
  • 29
  • 38
  • Can you share sample playbook or roles to run tasks in LXD containers through ssh or using lxd plugin? – gzala Dec 21 '21 at 09:52
  • LXD doesn't differ from normal hosts when accessed with ssh. – AlexD Dec 21 '21 at 09:54
  • Can we use dynamic inventories feature to run task inside LXD container through ansible? If so, please help me with the sample playbook or roles. I am facing this issue since 2 weeks. Lxd version: 4 (ubuntu 20.04 LTS) Ansible version: 5(ansible-core 2.12) --> ubuntu 20.04 LTS – gzala Dec 21 '21 at 10:01