I have so many HA machines that one of them is primary and the other is standby. I have this playbook that copies a config file from primary and then from standby on local machine then use those files as input for a python script:
- hosts: primary
remote_user: root
tasks:
- name: copy the config of primary to local
fetch:
src: /data1/cronjobs/gen_ddl
dest: /AnsibleDir/primary
flat: yes
- hosts: standby
remote_user: root
tasks:
- name: copy the config of standby to local
fetch:
src: /data1/cronjobs/gen_ddl
dest: /AnsibleDir/standby
flat: yes
- hosts: 127.0.0.1
connection: local
remote_user: root
tasks:
- name: run python script
shell: /AnsibleDir/driver.py
register: myshell_output
- name: copy the output to a local file
copy:
content: "{{ myshell_output.stdout }}"
dest: "/AnsibleDir/output.{{ host }}"
and I use this command:
ansible-playbook -i /Ansible/hostfile /Ansible/python.yml --extra-vars "host=test1"
in hostfile
I have this configuration:
[primary]
192.168.107.69
[standby]
192.168.107.70
I think that I should edit this file every time I want to run my playbook. so is it possible to have so many pairs of IPs?
for example something like this:
primary:1.1.1.1,standby:1.1.1.2
primary:1.1.1.3,standby:1.1.1.4
primary:1.1.1.5,standby:1.1.1.6
or can I assign each pair the variable I want instead of writing it in my command every time? like:
primary:1.1.1.1,standby:1.1.1.2,host:test1
primary:1.1.1.3,standby:1.1.1.4,host:test2
I searched a lot but I could't find anything and I'm new to ansible. Any suggestions?