小编Roo*_*999的帖子

Ansible - 检查本地是否存在多个文件并将其复制到远程

我对 Ansible 非常陌生,我正在尝试检查我的 Ansible 控制机中是否存在文件(至少应该有一个),如果存在,请将其复制到远程位置。

我想出了下面的内容,但是 ansible 正在检查远程而不是本地的文件。我也不太确定如何使用“with_items”。

---
- hosts: linux
  gather_facts: no
  vars:
   source_dir: /login/my_home
   server_type: WRITEVIEW
   files:
      - app.xslt
      - Configuration.xml
      - fcCN.xslt

  tasks:
   - name: Validate if file exists
     local_action: file path="{{ source_dir }}/{{ item }}" state=file
     with_items: files
Run Code Online (Sandbox Code Playgroud)

错误信息:

TASK [Validate if file exists] ****************************************************************************************************************************************** failed: [remoteserver_1 -> localhost] (item=files) => {"changed": false, "item": "files", "msg": "file (/login/my_home/files) is absent, cannot continue", "path": "/login/my_home/files", "state": "absent"} failed: [remoteserver_2 -> localhost] (item=files) => {"changed": false, "item": …

ansible ansible-2.x

3
推荐指数
1
解决办法
9233
查看次数

标签 统计

ansible ×1

ansible-2.x ×1