Firstly this post is different than other post on this error because it first works and then does not.
When pulling and installing an image from an ansible playbook with the tasks delegated to my remote docker host everything works, but when trying to use the connection plugin from the same collection (community.docker)
I get
fatal: [localhost -> instance-139.xxx.xxx.xxx]: FAILED! => {
"msg": "docker command not found in PATH"
}
I’ve seen one or two similar post, but they all speak of having a different the issue being a user that potentially lacks access. For my situation the user is the exact same (root). I would like to know why it works with everything but the connection plugin.
Error: fatal: [localhost -> instance-139.xxx.xxx.xxx]: FAILED! => {
"msg": "docker command not found in PATH"
}
Truncated version of my ansible playbook
- name: Create an API instance
hosts: localhost
gather_facts: no
collections:
- linode.cloud
- community.docker
tasks:
- block:
- name: Linode IPS
debug:
msg: "{{ linode_ips }}"
- name: Update apt and install dependencies
apt:
update_cache: yes
name: "{{ item }}"
force_apt_get: yes
state: present
loop:
- apt-transport-https
- ca-certificates
- curl
- gzip
- software-properties-common
- name: Add Docker GPG key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add Docker repository
apt_repository:
repo: deb https://download.docker.com/linux/ubuntu focal stable
state: present
- name: Install Docker
apt:
name: docker-ce
state: present
force_apt_get: yes
update_cache: yes
- name: Start and enable Docker
systemd:
name: docker
state: started
enabled: yes
- debug:
msg: "Registry: docker.registry.aksantinet.com/{{ host_group }}"
- name: Pull the image from the registry
community.docker.docker_image:
name: "docker.registry.aksantinet.com/{{ host_group }}"
tag: latest
source: pull
- name: Run Docker container
community.docker.docker_container:
name: "{{ container_name }}"
image: "docker.registry.aksantinet.com/{{ host_group }}"
network_mode: host
state: started
capabilities:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
privileged: yes
become: yes
- name: Copy LetsEncrypt from ansible to Docker
become: yes
block:
- lineinfile:
path: "test"
line: "example"
create: yes
state: present
- ansible.builtin.copy:
src: /etc/letsencrypt/
dest: /etc/letsencrypt/
- shell: nginx
vars:
ansible_docker_host: "{{ container_name }}"
ansible_connection: docker
- name: Instance added
debug:
msg: "Addded instance at {{ linode_ip }}"
delegate_to: "instance-{{ linode_ip }}"