我如何使用Ansible挂载单个文件?

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

我的远程主机上有一个目录,我想挂载到Docker容器中。该目录的问题在于,其目录及其文件本身需要特定的所有者和组。首先,我尝试过:

    ...some code...

        - name: setup jitsi-meet volumes
          file:
            path: "{{ item }}"
            state: directory
            owner: 999   # jvb / jicofo in videobrige / jicofo container
            group: 1000  # jitsi in videobrige / jicofo container
            mode: 0755
          with_items:
            - "{{ CONFIG }}/jicofo"
            - "{{ CONFIG }}/jvb"

    ...some code...

        # Video bridge
        - name: run jitsi-meet jvb image
          docker_container:
            name: jitsi-jvb
            ........
            volumes:
              "{{ CONFIG }}/jvb:/config"
            ........

    ...some code...

Ansible会与所需的所有者和组一起递归创建卷。因此,{{ CONFIG }}/jvb及其内容为999:1000jvb:jitsi)。但是,无论出于何种原因,在安装过程中,仅/config具有所需的所有者和组(999:1000jvb:jitsi),而/config的内容仍具有root:root。然后,我尝试按文件挂载文件(请参见下文),但是ansible拒绝让我这样做。有人知道如何解决此问题吗?

# Video bridge
- name: run jitsi-meet jvb image
  docker_container:
    name: jitsi-jvb
    ..........
    volumes:
      "{{ CONFIG }}/jvb:/config"
      "{{ CONFIG }}/jvb/logging.properties:/config/logging.properties"
      "{{ CONFIG }}/jvb/sip-communicator.properties:/config/sip-communicator.properties"

错误是:

ERROR! Syntax Error while loading YAML.
did not find expected key

The error appears to have been in '/FAKEPATH/docker-container-jitsi.yml': line 56, column 7, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

      "{{ CONFIG }}/jvb:/config"
      "{{ CONFIG }}/jvb/logging.properties:/config/logging.properties"
      ^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes.  Always quote template expression brackets when they
start a value. For instance:

    with_items:
      - {{ foo }}

Should be written as:

    with_items:
      - "{{ foo }}"
ansible docker-container
1个回答
1
投票

对我来说,这似乎是一个简单的语法问题。volumeList的破折号缺失:

...
volumes:
 - "{{ CONFIG }}/jvb:/config"
 - "{{ CONFIG }}/jvb/logging.properties:/config/logging.properties"
 - "{{ CONFIG }}/jvb/sip-communicator.properties:/config/sip-communicator.properties"
...
© www.soinside.com 2019 - 2024. All rights reserved.