Is it possible to have pair of IPs in Ansible?
Q: Is it possible to have a pair of IPs in Ansible?


A: Yes. It is possible. For example, it might be useful to create groups in the inventory with all pieces of information.

[primary]
1.1.1.1
1.1.1.3
1.1.1.5

[standby]
1.1.1.2
1.1.1.4
1.1.1.6

[ha]
1.1.1.1 stdby=1.1.1.2
1.1.1.3 stdby=1.1.1.4
1.1.1.5 stdby=1.1.1.6


It's possible to simplify the fetching of the configuration.

- hosts: primary, standby
  remote_user: root
  tasks:
  - name: copy the config to local
    fetch:
      src: /data1/cronjobs/gen_ddl
      dest: /AnsibleDir/conf


Without flat: yes the configuration files will be stored in

/AnsibleDir/conf/{{ inventory_hostname }}/data1/cronjobs/gen_ddl


Then it's possible to reference the configuration files by the inventory hostname. For example groups['primary'] (secondary the same way). Take a look at myshell_output and select the data for content and dest from the items

- hosts: 127.0.0.1
  connection: local
  remote_user: root
  tasks:
  - name: loop primary config
    command: "/AnsibleDir/driver.py
              /AnsibleDir/conf/{{ item }}/data1/cronjobs/gen_ddl"
    register: myshell_output
    loop: "{{ groups['primary'] }}"
  - name: copy the output to a local file
    copy:
      content: "{{ &lt;SELECT-FROM-ITEM&gt; }}"
      dest: "/AnsibleDir/output.{{ &lt;SELECT-FROM-ITEM&gt; }}"
    loop: "{{ myshell_output.results }}"


To reference primary/standby pairs use group ha. For example the play below changes the configuration both at primary and standby for all hosts in ha.

- hosts: ha
  tasks:
    - name: Change configuration at primary
      lineinfile:
        path: /AnsibleDir/conf/{{ inventory_hostname }}/data1/cronjobs/gen_dd
        regexp: &lt;ADD-REGEXP&gt;
        line: &lt;ADD-LINE&gt;
    - name: Change configuration at standby
      lineinfile:
        path: /AnsibleDir/conf/{{ hostvars[inventory_hostname].stdby }}/data1/cronjobs/gen_dd
        regexp: &lt;ADD-REGEXP&gt;
        line: &lt;ADD-LINE&gt;



  Q: I need to find the differences of configuration files in 2 machines. they need to be the same. In python script, it will find the differences and fix them. So I need to have both configurations on my local then run the python script for them.


A: Fix the configuration files in 2 machines

- hosts: ha
  tasks:
    - name: Fix primary and standby config
      command: "/AnsibleDir/driver.py
                /AnsibleDir/conf/{{ inventory_hostname }}/data1/cronjobs/gen_ddl
                /AnsibleDir/conf/{{ hostvars[inventory_hostname].stdby }}/data1/cronjobs/gen_ddl"