1

Trying to figure out the best way to get ansible to do its magic within the containers. Was thinking of using ssh in each container, but then that is server-dependent. or I have to come via the proxy which seems like more work than should be necessary. Again, I am already creating containers, deleting etc… I am talking about running commands within the container with ansible not via lxc exec containername bash which I can do now. Anyone figure out the best way to do it.

gzala
  • 21
  • 2
  • Does this answer your question? [Ansible (SSH + LXD) plugin](https://serverfault.com/questions/1087866/ansible-ssh-lxd-plugin) – AlexD Dec 21 '21 at 09:27
  • Can I ask why you want to? What is it that needs doing to these containers that requires Ansible? – shearn89 Dec 21 '21 at 15:35
  • 1
    I am trying to create a project for hosting platform. For that, i am using LXD containers and Ansible. As i m having issue to run task inside LXD container through ansible. Can you help me out? – gzala Dec 21 '21 at 15:41

1 Answers1

1

taken from https://docs.ansible.com/ansible/latest/collections/community/general/lxc_container_module.html#examples

you can try the following:

- name: Run a complex command within a "running" container
  community.general.lxc_container:
    name: test-container-started
    container_command: |
      apt-get update
      apt-get install -y curl wget vim apache2
      echo 'hello world.' | tee /opt/started
      if [[ -f "/opt/started" ]]; then
          echo 'hello world.' | tee /opt/found-started
      fi
Roman Spiak
  • 583
  • 3
  • 11
  • I am running lxd container and it does not seems to be working with the above commands. – gzala Dec 27 '21 at 04:28
  • as this is a part of official documentation I suggest you open an issue on official github of ansible community.general.lxc_container module with detailed logs as to what is failing and how – Roman Spiak Jan 15 '22 at 19:51