This could be a simple issue easy to be resolved but I'm just starting testing it on mainframe, I'm not able to collect the result from a command and save it to a file , it gives me the known error "UnboundLocalError: local variable 'local_content' referenced before assignment" - but the I've tried to define it in a different variable, (setfact) tried loading it from hostvars, using block, etc. the "reference before assignment" doesn´t make much sense as i've tested it and confirmed it can be loaded inside that play. Would you know the best way to save any command's result to a file / dataset.
---
- name: playbook - command - saving to file
hosts: all
gather_facts: false
environment:
ZOAU_HOME: "{{ ZOAU }}"
PYTHONPATH: "{{ ZOAU }}/lib"
LIBPATH: "{{ ZOAU }}/lib:{{ PYZ }}/lib:/lib:/usr/lib:."
PATH: "{{ ZOAU }}/bin:{{ PYZ }}/bin:/bin:/usr/sbin:/var/bin"
_BPXK_AUTOCVT: "ON"
_CEE_RUNOPTS: "FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)"
_TAG_REDIR_ERR: "txt"
_TAG_REDIR_IN: "txt"
_TAG_REDIR_OUT: "txt"
LANG: "C"
collections:
- ibm.ibm_zos_core
vars:
ansible_ssh_pipelining: no
tasks:
- name: testing command and saving result
block:
- name: issuing comand adn collecting results
zos_operator:
cmd: "d a,l"
register: resultado
- name: "Set variables - only to test"
set_fact:
display: "{{ resultado.content }}"
- name: debuging
debug:
var: display
- name: saving to file
zos_copy:
content: "{{ display }}"
dest: /u/LO1754A/Ansible/Files/display.txt
The full traceback is:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 147, in run
res = self._execute()
File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 665, in _execute
result = self._handler.run(task_vars=variables)
File "/usr/share/ansible/collections/ansible_collections/ibm/ibm_zos_core/plugins/action/zos_copy.py", line 152, in run
os.remove(local_content)
UnboundLocalError: local variable 'local_content' referenced before assignment
fatal: [nwrd]: FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}
------------------------------
Fernando Alfredo Custodio
------------------------------