我试图通过在本地存储更改的机器的主机名来增强我的剧本,并且我想尽可能多地使用 ansible 模块,这就是为什么我选择使用 th copy 模块来进行存储:
我的剧本看起来像这样:
- name: test connectivity
hosts: all
tasks:
- name: ping
ping:
- name: change default gateway address
replace:
path: /etc/network/interfaces
regexp: '(up route add default gw [\d]*\.[\d]*.[\d]*)\.[\d]*$'
replace: '\1.254'
backup: yes
when: (ansible_facts['distribution'] == "Debian")
- name: restart networking service
service:
name: networking
state: restarted
when: (ansible_facts['distribution'] == "Debian")
- name: change default gateway address on Redhat
replace:
path: /etc/sysconfig/network-scripts/ifcfg-eth0
regexp: '(GATEWAY=[\d]*\.[\d]*.[\d]*)\.[\d]*$'
replace: '\1.254'
backup: yes
when: (ansible_facts['distribution'] == "RedHat")
- name: restart networking service for Redhat
service:
name: network
state: restarted
when: (ansible_facts['distribution'] == "RedHat")
- name: register changed hosts locally
copy:
content: "{{ ansible_facts['hostname'] }}"
dest: "/tmp/changed.txt"
delegate_to: localhost
但以下错误不断弹出:
TASK [register changed hosts locally] *******************************************************************************************************************************************************************************************************
fatal: [name of host 1]: FAILED! => {"changed": false, "checksum": "df1496ad2c4ffed5abfad0a9fc69f7fb3a039765", "msg": "Unsupported parameters for (copy) module: delegate_to Supported parameters include: _original_basename, attributes, backup, checksum, content, delimiter, dest, directory_mode, follow, force, group, local_follow, mode, owner, regexp, remote_src, selevel, serole, setype, seuser, src, unsafe_writes, validate"}
fatal: [name of host 2]: FAILED! => {"changed": false, "checksum": "b75217f7ab69a82dd5aea389fcd8eacee15743e5", "msg": "Unsupported parameters for (copy) module: delegate_to Supported parameters include: _original_basename, attributes, backup, checksum, content, delimiter, dest, directory_mode, follow, force, group, local_follow, mode, owner, regexp, remote_src, selevel, serole, setype, seuser, src, unsafe_writes, validate"}
所以我想知道是不是因为我使用的复制参数?究竟是哪一个?