【发布时间】:2019-09-25 17:39:45
【问题描述】:
我是 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
错误信息:
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": "files", "msg": "file (/login/my_home/files) is absent, cannot continue", "path": "/login/my_home/files", "state": "absent"}
【问题讨论】:
-
@ChenA.:感谢您的建议,但我想在复制之前检查本地是否存在多个文件。 Atlesat 应该存在一个文件。
标签: ansible ansible-2.x