docker - Ansible relative path from variable - Stack Overflow

admin2025-04-21  2

I'm not able to fix this problem. Not with Google, not with AI.

I got a folder / git structure that I have my playbooks folder on the first level. My docker folder contains folders named after my docker services with compose.yml files inside.

I have the following playbook and I'm trying to execute it in Semaphore (Ansible UI).

The problem is that this relative path I want to point to (docker folder) is not found.

It will always end in this error:

failed: [azure] (item={'changed': False, 'stat': {'exists': False}, 'invocation': {'module_args': {'path': '/opt/stacks/watchtower', 'follow': False, 'get_checksum': True, 'get_mime': True, 'get_attributes': True, 'checksum_algorithm': 'sha1'}}, 'failed': False, 'item': '/tmp/semaphore/repository_1_14/playbooks/../docker/watchtower',

The playbook:

---
# This Ansible playbook is designed to copy Docker Compose files to specified hosts.
- name: Copy Docker Compose Files
  hosts: all
  become: true

  tasks:
    - name: Ensure /opt/stacks directory exists
      file:
        path: /opt/stacks
        state: directory
        mode: '0755'

    - name: Copy Docker Compose directories to vps hosts
      copy:
        src: "{{ playbook_dir }}/../docker/{{ item }}"
        dest: "/opt/stacks/"
        remote_src: yes
      with_items:
        - watchtower
        - dockerproxy
        - portainer-agent
      when: "'vps' in group_names"

    - name: Copy Docker Compose directories to vps hosts
      copy:
        src: "{{ item.item }}"
        dest: "/opt/stacks/"
        remote_src: yes
      with_items: "{{ stack_dirs.results }}"
      when: item.stat.exists == false and "'vps' in group_names"

    - name: Copy uptime-kuma directory to oracle
      copy:
        src: "{{ playbook_dir }}/../docker/uptime-kuma"
        dest: "/opt/stacks/"
        remote_src: yes
      when: inventory_hostname == 'oracle'

I'm not able to fix this problem. Not with Google, not with AI.

I got a folder / git structure that I have my playbooks folder on the first level. My docker folder contains folders named after my docker services with compose.yml files inside.

I have the following playbook and I'm trying to execute it in Semaphore (Ansible UI).

The problem is that this relative path I want to point to (docker folder) is not found.

It will always end in this error:

failed: [azure] (item={'changed': False, 'stat': {'exists': False}, 'invocation': {'module_args': {'path': '/opt/stacks/watchtower', 'follow': False, 'get_checksum': True, 'get_mime': True, 'get_attributes': True, 'checksum_algorithm': 'sha1'}}, 'failed': False, 'item': '/tmp/semaphore/repository_1_14/playbooks/../docker/watchtower',

The playbook:

---
# This Ansible playbook is designed to copy Docker Compose files to specified hosts.
- name: Copy Docker Compose Files
  hosts: all
  become: true

  tasks:
    - name: Ensure /opt/stacks directory exists
      file:
        path: /opt/stacks
        state: directory
        mode: '0755'

    - name: Copy Docker Compose directories to vps hosts
      copy:
        src: "{{ playbook_dir }}/../docker/{{ item }}"
        dest: "/opt/stacks/"
        remote_src: yes
      with_items:
        - watchtower
        - dockerproxy
        - portainer-agent
      when: "'vps' in group_names"

    - name: Copy Docker Compose directories to vps hosts
      copy:
        src: "{{ item.item }}"
        dest: "/opt/stacks/"
        remote_src: yes
      with_items: "{{ stack_dirs.results }}"
      when: item.stat.exists == false and "'vps' in group_names"

    - name: Copy uptime-kuma directory to oracle
      copy:
        src: "{{ playbook_dir }}/../docker/uptime-kuma"
        dest: "/opt/stacks/"
        remote_src: yes
      when: inventory_hostname == 'oracle'
Share Improve this question edited Jan 23 at 7:56 DuesserBaest 3,0017 silver badges28 bronze badges asked Jan 22 at 22:43 CptDayDreamerCptDayDreamer 1,8147 gold badges31 silver badges79 bronze badges 4
  • 3 When we ask "what did you try?", we mean the specific technical fixes you attempted. We don't mean "Google" or "AI", we mean the things Google told you to do or an AI told you to do (or your own troubleshooting experience and knowledge told you to do) that you actually tried. Often, knowing exactly how prior attempts failed can be informative. Knowing that someone tried things they got from Google without knowing what those things are -- specifically -- is completely uninformative to the point of being useless. – Charles Duffy Commented Jan 22 at 22:56
  • 2 (...often, when an attempt failed with a different error message, the differences can imply that someone got closer to the solution than they were when they started, or successfully resolved their problem but didn't realize it because it was masked by a new and different problem). – Charles Duffy Commented Jan 22 at 22:59
  • If you use just ../docker/{{ item }}, would it work? – U880D Commented Jan 23 at 14:41
  • @U880D this ends up in the error Source ../docker/watchtower not found – CptDayDreamer Commented Jan 23 at 22:48
Add a comment  | 

1 Answer 1

Reset to default 0

Your src: "{{ playbook_dir }}/../docker/{{ item }}" does not create a real path.

/tmp/semaphore/repository_1_14/playbooks/../docker/watchtower does not exist and it does not equate the /tmp/semaphore/repository_1_14/docker/watchtower you need.

Try src: "docker/{{ item }}".

转载请注明原文地址:http://anycun.com/QandA/1745225444a90455.html