Ansible 作业复制到远程时会创建奇怪的目录结构

问题描述 投票:0回答:1

我有一本这样的剧本。很简单。它将文件复制到远程并执行 docker compose 命令。

---
- name: Deploy Docker Compose Application
  hosts: all
  become: true
  vars:
    workspace_dir: /home/josh/db
    backup_dir: /home/josh/backups
    backup_filename: "db_{{ ansible_date_time.iso8601 }}.tar.gz"

  tasks:
    - name: Create backup directory
      file:
        path: "{{ backup_dir }}"
        state: directory
        mode: '0755'

    - name: Check if workspace directory exists
      stat:
        path: "{{ workspace_dir }}"
      register: workspace_stat

    - name: Backup existing workspace
      archive:
        path: "{{ workspace_dir }}"
        dest: "{{ backup_dir }}/{{ backup_filename }}"
        format: gz
      when: workspace_stat.stat.exists and workspace_stat.stat.isdir

    - name: Clean existing workspace directory
      file:
        path: "{{ workspace_dir }}"
        state: absent

    - name: Create workspace directory
      file:
        path: "{{ workspace_dir }}"
        state: directory
        mode: '0755'

    - name: Copy local files
      copy:
        src: "{{ item }}"
        dest: "{{ workspace_dir }}/{{ item }}"
        mode: '0644'
      loop:
        - .env.production
        - docker-compose.production.yml

    - name: Copy postgres configuration directory
      copy:
        src: postgres/
        dest: "{{ workspace_dir }}/postgres/"
        mode: '0644'
        directory_mode: '0755'

    - name: Copy loki configuration directory
      copy:
        src: loki/
        dest: "{{ workspace_dir }}/loki/"
        mode: '0644'
        directory_mode: '0755'

    - name: Create required directories
      file:
        path: "{{ workspace_dir }}/{{ item }}"
        state: directory
        mode: '0755'
      loop:
        - backups
        - postgres/logs

    - name: Start Docker service
      systemd:
        name: docker
        state: started
        enabled: yes

    - name: Deploy with docker compose
      shell:
        cmd: docker compose -f docker-compose.production.yml up -d --remove-orphans
        chdir: "{{ workspace_dir }}"

    - name: Check docker compose status
      shell:
        cmd: docker compose -f docker-compose.production.yml ps
        chdir: "{{ workspace_dir }}"
      register: compose_status

    - name: Display docker compose output
      debug:
        var: compose_status.stdout_lines

除非它尝试复制

postgres
目录及其内容。它出错了。它创建了一个模仿文件名的奇怪目录结构。

db
├── backups
├── docker-compose.production.yml
├── loki
│   └── local-config.yaml
└── postgres
    ├── logs
    ├── pg_hba.conf
    │   └── pg_hba.conf
    └── postgresql.conf
        └── postgresql.conf

如您所见,

pg_hba.conf
postgresql.conf
是在匹配名称的无关文件夹内创建的。

有人遇到过这种情况吗?这很奇怪,因为复制

loki
配置的作业按预期执行,而
postgres
作业失败。

如有任何意见,我们将不胜感激!

ubuntu ansible
1个回答
0
投票

可能是文件系统问题。哈哈

© www.soinside.com 2019 - 2024. All rights reserved.