Hi,
I have the following ansible script
$ cat generated-head-node.yaml
- hosts: all
tasks: - name: Run multiple commands
command: “{{item}}”
with_items: - pwd
- ls
register: out - debug: msg=“{{ item.stdout_lines }}”
with_items: “{{ out.results }}”
I am unable to print out just the output results in stdout_lines, it prints out other information which I’d like to suppress
How do I achieve that ?
PLAY [all] *********************************************************************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************************************************
ok: [192.168.8.45]
TASK [Run multiple commands] ***************************************************************************************************************************************************
changed: [192.168.8.45] => (item=pwd)
changed: [192.168.8.45] => (item=ls)
TASK [debug] *******************************************************************************************************************************************************************
ok: [192.168.8.45] => (item={‘changed’: True, ‘end’: ‘2020-01-23 17:58:52.021083’, ‘stdout’: ‘/home/nyue’, ‘cmd’: [‘pwd’], ‘rc’: 0, ‘start’: ‘2020-01-23 17:58:52.009380’, ‘stderr’: ‘’, ‘delta’: ‘0:00:00.011703’, ‘invocation’: {‘module_args’: {‘creates’: None, ‘executable’: None, ‘_uses_shell’: False, ‘strip_empty_ends’: True, ‘_raw_params’: ‘pwd’, ‘removes’: None, ‘argv’: None, ‘warn’: True, ‘chdir’: None, ‘stdin_add_newline’: True, ‘stdin’: None}}, ‘stdout_lines’: [‘/home/nyue’], ‘stderr_lines’: , ‘failed’: False, ‘item’: ‘pwd’, ‘ansible_loop_var’: ‘item’}) => {
“msg”: [
“/home/nyue”
]
}
ok: [192.168.8.45] => (item={‘changed’: True, ‘end’: ‘2020-01-23 17:58:53.644286’, ‘stdout’: ‘Desktop\nDocuments\nDownloads\nMusic\nPictures\nPublic\nTemplates\nVideos’, ‘cmd’: [‘ls’], ‘rc’: 0, ‘start’: ‘2020-01-23 17:58:53.638312’, ‘stderr’: ‘’, ‘delta’: ‘0:00:00.005974’, ‘invocation’: {‘module_args’: {‘creates’: None, ‘executable’: None, ‘_uses_shell’: False, ‘strip_empty_ends’: True, ‘_raw_params’: ‘ls’, ‘removes’: None, ‘argv’: None, ‘warn’: True, ‘chdir’: None, ‘stdin_add_newline’: True, ‘stdin’: None}}, ‘stdout_lines’: [‘Desktop’, ‘Documents’, ‘Downloads’, ‘Music’, ‘Pictures’, ‘Public’, ‘Templates’, ‘Videos’], ‘stderr_lines’: , ‘failed’: False, ‘item’: ‘ls’, ‘ansible_loop_var’: ‘item’}) => {
“msg”: [
“Desktop”,
“Documents”,
“Downloads”,
“Music”,
“Pictures”,
“Public”,
“Templates”,
“Videos”
]
}
PLAY RECAP *********************************************************************************************************************************************************************
192.168.8.45 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Cheers