I created a Worflow job in awx containing 2 jobs:
- Job 1 is using the credentials of the windows server where we get the json file from. It reads the content and put it in a variable using
set_stats
- Job2 is using the credential of the server where to upload the json file. It reads the content of the variable set in the job 1 in the
set_stats
task and creates a json file with the content.
First job:
- name: get content
win_shell: 'type {{ file_dir }}{{ file_name }}'
register: content
- name: write content
debug:
msg: "{{ content.stdout_lines }} "
register: result
- set_fact:
this_local: "{{ content.stdout_lines }}"
- set_stats:
data:
test_stat: "{{ this_local }}"
- name: set hostname in a variable
set_stats:
data:
current_hostname: "{{ ansible_hostname }}"
per_host: no
Second job
- name: convert to json and copy the file to destination control node.
copy:
content: "{{ test_stat | to_json }}"
dest: "/tmp/{{ current_hostname }}.json"
How can I get the current_hostname
, so that the the created json file is named <original_hostname>.json
? In my case its concatenating the two hosts which I passed in the first job.