I’m trying to connect to a remote host and then jump into a lxc container. I’m using Ubuntu 20.04 and I have installed lxc using snap.
Here’s my Ansible task:
---
- hosts: all
become: yes
become_method: sudo
tasks:
- name: Run a complex command within a "running" container
community.general.lxc_container:
name: mycontainer
container_command: |
apt-get update
touch we_have_access.txt
I’m stumped at this error message:
{"changed": false, "msg": "Failed to find required executable \"lxc-create\" in paths: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"}
I thought lxc-create was an old command as there doesn’t seem to be any lxc-utils in snap. Is the Ansible package maintained up to the latest version of lxc or should I go back to using the lxc version from apt that’s supported by lxc-utils?
I’m struggling to get the above to work where it comes to the container_command. I’m not able to get any of the commands to run however it says that all the tasks have completed successfully.
I also try to find answers for this questions, but no one respond I try to execute command in LXC container.
I have playbook:
- name: Run a command in a container and ensure its it in a "frozen" state.
community.general.lxc_container:
name: Nginx
container_command: |
echo 'hello world.' | tee /opt/frozen
But got error:
root@Ansible:/etc/ansible/playbooks# ansible-playbook test_commands.yaml
PLAY [devel-lxd01] ****************************************************************************************************************************
TASK [Gathering Facts] ************************************************************************************************************************
ok: [devel-lxd01]
TASK [Run a command in a container and ensure its it in a "frozen" state.] ********************************************************************
fatal: [devel-lxd01]: FAILED! => {"changed": false, "msg": "Failed to find required executable \"lxc-create\" in paths: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"}
PLAY RECAP ************************************************************************************************************************************
devel-lxd01 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
root@Ansible:~# which lxc-ls
/usr/bin/lxc-ls
- name: Run a command in a container and ensure its it in a "frozen" state.
community.general.lxc_container:
name: Nginx
container_command: |
echo 'hello world.' | tee /opt/frozen
TASK [Run a command in a container and ensure its it in a "frozen" state.] ********************************************************************
fatal: [devel-lxd01]: FAILED! => {"changed": false, "msg": "Failed to find required executable \"lxc-create\" in paths: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"}
PLAY RECAP ************************************************************************************************************************************
devel-lxd01 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
When I use community.general.lxd_container:
- name: Run a command in a container and ensure its it in a "frozen" state.
community.general.lxd_container:
name: Nginx
container_command: |
echo 'hello world.' | tee /opt/frozen
I get other error
TASK [Run a command in a container and ensure its it in a "frozen" state.] ********************************************************************
fatal: [devel-lxd01]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (community.general.lxd_container) module: container_command. Supported parameters include: config, client_key (key_file), target, state, url, ephemeral, architecture, snap_url, source, type, wait_for_ipv4_addresses, timeout, force_stop, name, profiles, devices, client_cert (cert_file), trust_password, ignore_volatile_options."}
PLAY RECAP ************************************************************************************************************************************
devel-lxd01 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0