Access LXC Container using Ansible

Viewed 341

I'm using Ansible to manage the LXC containers (still learning to do so). I'm stuck while trying to run some task inside the LXC. I tried to use the lxc connection plugin but no luck so far.

Goal: ansible ==> ssh ==> vm / barematel ==> ansible connection plugin (lxc) ==> container => run some tasks

Ansible Version

2.5.1

Hosts

[default]
staging-host ansible_ssh_host=10.10.10.104 ansible_ssh_user=root

Testing Playbook:

- name: Create a Container
  lxc_container:
    name: "{{ container_name }}"
    container_log: true
    template: ubuntu
    state: started
    template_options: --release bionic

- name: Add Dynamic Host
  add_host:
    name: "{{ container_name }}"
    ansible_connection: lxc
    remote_addr: "{{ container_name }}"

- name: Try to access the container
  delegate_to: "{{ container_name }}"
  shell: uname -a

Output

task path: /media/ansible/roles/ha_lxc/tasks/haproxy.yml:39
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/packaging/os/apt.py
<ha-lb-1> THIS IS A LOCAL LXC DIR
fatal: [staging-host]: FAILED! => {
    "msg": "ha-lb-1 is not running"
}
  to retry, use: --limit @/media/ansible/ha.retry
PLAY RECAP **********************************************************************************************************************************************************************************************
staging-host                : ok=2    changed=0    unreachable=0    failed=1   

I'm trying to solve this since last 3 days but no luck. I would really appreciate the suggestion, tips, help.

0 Answers
Related