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.
-
Does this answer your question? Ansible (SSH + LXD) plugin– AlexDDec 21, 2021 at 9:27
-
Can I ask why you want to? What is it that needs doing to these containers that requires Ansible?– shearn89Dec 21, 2021 at 15:35
-
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?– gzalaDec 21, 2021 at 15:41
1 Answer
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
-
I am running lxd container and it does not seems to be working with the above commands.– gzalaDec 27, 2021 at 4: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 Jan 15 at 19:51