I am using 2 playbooks linked, there details mentioned below.
playbook1: collect raw data from multiple machines
- hosts: target_1
gather_facts: false
tasks:
- name: Register a new value
shell: df -h|awk '{gsub("%","|");print $5 $6}'
register: PLAY1VAR
- debug: msg="{{PLAY1VAR.stdout}}"
- name: Register a new value
shell: hostname
register: PLAY2VAR
- debug: msg="{{PLAY2VAR.stdout}}"
- name: Register dummy host with variable
add_host:
name: "DUMMY_HOST"
PLAY1VAR_NEW: " {{ PLAY1VAR.stdout }}"
- name: Register dummy host with variable
add_host:
name: "DUMMY_HOST_1"
PLAY2VAR_NEW: " {{ PLAY2VAR.stdout }}"
- hosts: target_2
gather_facts: false
tasks:
- name: Register a new value
playbook2:parse data using python script
- hosts: localhost
gather_facts: false
tasks:
- name: Echo the output - PLAY1 variable vaule
command: python3 /opt/diskspace_watcher/watcher.py '{{hostvars['DUMMY_HOST']['PLAY1VAR_NEW']}}' '{{hostvars['DUMMY_HOST_1']['PLAY2VAR_NEW']}}'
register: PLAY2_RESULTS
- debug: msg="{{PLAY2_RESULTS.stdout}}"
I am passing couple of variables from the first playbook to another, when I am running this for just one host it is working as expected but when trying to run for multiple host it is unable to pass the arguments for all the host mentioned in the inventory file and is just picking up one variable for a particular host.
I am looking for a way to get this executed. Any help/idea is appreciated!!