I write a simple playbook to copy some configuration files on a certain machine. I need to copy this file in a different host too for backup. Is possible to declare different host in the same playbook? I need this cause my "backup host" can be different and I retrieve it from the hostname I use. I tried both copy and raw module and nothing seems to work
here the example of playbook
- name: find file
find:
file_type: directory
paths: /prd/viv/dat/repository/
patterns: "{{inventory_hostname}}"
recurse: yes
register: find
delegate_to: localhost
- name: Copy MASTER
raw: echo xmonit$(echo {{find.files[0].path}} | cut -d "/" -f7 )
delegate_to: localhost
register: xmonit
- debug:
msg: "{{xmonit.stdout}}"
- name: Copy MASTER raw
raw: sshpass -p "mypass" scp {{find.files[0].path}}/master.cfg myuser@{{xmonit.stdout}}:/prd
delegate_to: localhost
#- name: Copy MASTER
#copy:
#src: "{{find.files[0].path}}/master.cfg"
#dest: /prd/cnf/dat/{{inventory_hostname}}/
edit: if I use the copy module the destination remains that of the main host while the goal is to copy to a third host. I need to declare a different host for this single task
- name: Copy MASTER
copy:
src: "{{find.files[0].path}}/master.cfg"
dest: /prd/cnf/dat/{{inventory_hostname}}/
nothing seems to workis not an accurate description of your current problems. 3) What is wrong exactly with thecopymodule which seems the perfect candidate for this job ? - Please update your question with more precise infolocalhosttosome_other_host. Ifsome_other_hostis not be the current host in play, simplydelegate_to: some_other_host.copymodule copies files from localhost (i.e. ansible controller) to the remote target (i.e. current host in play). If youdelegate_to, it copies from localhost to the delegated target