Score:0

Ansible (SSH + LXD) plugin

lu flag

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
djdomi avatar
za flag
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.
Score:0
jp flag

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

gzala avatar
lu flag
Can you share sample playbook or roles to run tasks in LXD containers through ssh or using lxd plugin?
jp flag
LXD doesn't differ from normal hosts when accessed with ssh.
gzala avatar
lu flag
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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.