嗨,我有一个从远程服务器获取信息并将其放在本地服务器上的剧本,是否可以添加一个将该文件复制到本地并将其放置在特定主机上的剧本?我计划在下面对它进行编码,或者你有任何建议,什么是最好的方法?尽管服务器1不在剧本使用的库存文件中。
- name: Get compliance reporting from remote
fetch:
src: /tmp/compliancereporting.out
dest: /home/ansible/linuxpatchingv2/OUTGOING-COMPLIANCE_v2/inventory_{{ '%y%m%d%H%M%S' | strftime }}
flat: yes
- name: Copy the fetch file
host: server1
copy:
src: /home/ansible/linuxpatchingv2/OUTGOING-COMPLIANCE_v2/inventory_*
dst: /tmp/
获取模块将文件从远程主机复制到<dest>/ansible_hostname
的Ansible控制机。
例如,对于host1.example.co
和dest: /home/ansible/linuxpatchingv2
:
/home/ansible/linuxpatchingv2/host1.example.co/tmp/compliancereporting.out
所以在你的剧本里,你会有两个剧本。第一次播放将fetch
文件发送到Ansible控制机,第二次播放将第一次播放中提取的文件copy
发送到远程机。
- name: Fetch the file from host1.example.co
hosts: host1.example.co
tasks:
- name: Fetch the file
fetch:
src: /tmp/compliancereporting.out
dest: /home/ansible/linuxpatchingv2/
- name: Copy the file to remote host server1
hosts: server1
tasks:
- name: Copy report to remote path
copy:
src: /home/ansible/linuxpatchingv2/host1.example.co/tmp/compliancereporting.out
dest: /tmp/