Score:0

Running tasks inside LXD container through ansible

lu flag

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.

jp flag
Does this answer your question? [Ansible (SSH + LXD) plugin](https://serverfault.com/questions/1087866/ansible-ssh-lxd-plugin)
cn flag
Can I ask why you want to? What is it that needs doing to these containers that requires Ansible?
gzala avatar
lu flag
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?
Score:1
it flag

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
gzala avatar
lu flag
I am running lxd container and it does not seems to be working with the above commands.
Roman Spiak avatar
it flag
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
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.