How could I save multiple registered variables to a file using Ansible?
Goal: I would like to gather information from various commands and save the result
My Playbook looks like this:
- name: Find the process
shell: ps auxk +rss | tail
register: process_name
- name: Check system activity
shell: sar -W
register: sar_output
- name: Run smem
command: smem -s swap
when:
- ansible_facts['distribution'] == "RedHat"
- ansible_facts['distribution_major_version'] == "7"
register: smem_usage
ignore_errors: yes
- name: Save content to a file
local_action: copy content="{{ item }}" dest="/tmp/swap_info.txt"
with_items:
- "{{ process_name }}"
- "{{ sar_output }}"
- "{{ smem_usage }}"
But the /tmp/swap_info.txt contains only the last registered variable i.e - smem_usage info.
set_facttask, then run thecopymodule - ilias-sp