【发布时间】:2020-09-11 11:16:46
【问题描述】:
如果存在任何文件,我需要将 hosts_example 或 hosts_Example 重命名为 hosts_real
- name: Playbook to Standardize Hosts
hosts: test
vars:
destpath: /etc/hosts_real
filename: [ /etc/hosts_example,/etc/hosts_Example ]
tasks:
- name: Check if file exists
stat:
path: "{{ item }}"
with_items:
- "{{ filename }}"
register: check_file_name
- debug:
msg: "{{check_file_name}}"
- name: Rename file
command: mv "{{ item }}"{{destpath}}"
with_items:
- "{{ check_file_name.results }}"
when: item.stat.exists == true
我试过了,但出现错误,无法达到预期的结果
【问题讨论】:
-
嗨!请在问题中包含错误消息。
-
看起来您可能需要在
mv命令的两个参数之间留一个空格。我认为你也有引用问题。
标签: linux ansible hostname ansible-template