Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用ansible装载单个文件?_Ansible_Docker Container - Fatal编程技术网

如何使用ansible装载单个文件?

如何使用ansible装载单个文件?,ansible,docker-container,Ansible,Docker Container,我的远程主机上有一个目录,我想把它装入docker容器。这个目录的问题是,它的文件和它本身需要一个特定的所有者和组。首先,我试过: ...some code... - name: setup jitsi-meet volumes file: path: "{{ item }}" state: directory owner: 999 # jvb / jicofo in vid

我的远程主机上有一个目录,我想把它装入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:1000
jvb:jitsi
)。但是,无论出于何种原因,在装载过程中,只有
/config
具有所需的所有者和组(
999:1000
jvb:jitsi
),而
/config
的内容仍然具有
根目录:根目录
。然后,我尝试一个文件一个文件地挂载(见下文),但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 }}"

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

...
volumes:
 - "{{ CONFIG }}/jvb:/config"
 - "{{ CONFIG }}/jvb/logging.properties:/config/logging.properties"
 - "{{ CONFIG }}/jvb/sip-communicator.properties:/config/sip-communicator.properties"
...

这就是由此产生的问题。。但是我需要将ssh作为root用户连接到远程机器。作为普通用户运行容器不是进一步参考的选项^^:这个答案解决了我的问题,但问题本身并没有解决。为了以正确的方式设置属于这些容器的这些特殊图像的所有者和组,需要采用不同的方法。以普通用户身份运行映像,或者(如果不可能)手动更改权限,重新启动容器,将文件(logging.properties和sip communicator.properties)提取到本地计算机,并在.yaml文件中包含一个具有所需所有者/组值的复制任务。如果您现在运行这些图像,它们将不会创建这些文件,因为它们已经存在。