0
votes

Code Below Runs fine until it errors out on the Save locally task

 - local_action: file dest=firewallinfo.txt  state=touch

    - name: "Gather firewall information"
      script: firewall.sh
      register: output
    - debug: var=output

    - name: Firewall Name
      raw: hostname
      register: output2

    - debug: var=output2


    - name: the file
      raw: cat "{{item}}".csv
      with_items: '{{output2.stdout_lines}}'
      register: output3

    - debug: var=output3

This is where my code stops working. Anyone know why?

- name: save locally
  local_action: lineinfile dest=firewallinfo.txt  line="{{item}}"
  with_items: '{{output3.stdout_lines}}'
1
Do you get any output? - Railslide
I get the debug of - debug: var=output3 to work but when i try to take the stdout_lines of output3 and put into a file it gives me this error [DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a fatal error.. This feature will be removed in a future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg. - ehuck

1 Answers

0
votes

Variable output3 is a result of muti-item task.
So output3 is a dict with results list in it.
You need output3.results[i].stdout_lines[j].

Change your task to:

- name: save locally
  local_action: lineinfile dest=firewallinfo.txt  line="{{item}}"
  with_items: "{{ output3.results | sum(attribute='stdout_lines', start=[]) | list }}"

It will combine all stdout_lines in every result and give you a flat list to iterate.