Find files starting with <string> -- Frustration

50 views
Skip to first unread message

John Harmon

unread,
Aug 24, 2017, 6:43:09 PM8/24/17
to Ansible Project
Although my current playbook doesn't look for ifcfg files directly, I am just trying to grab a list of files and it is failing.  I can't, for the life of me, figure out why.  If I change the find: to a command: and then run an ls, it works......  wondering if someone can put me on the right path.  Not making any real progress on my own.....

Ultimately I am trying to find files starting with ifcfg- in the specified directory.

Side question:  Where can I find a list of debug output types for my vars (ie. stdout, stdout_lines, etc)?

Thanks in advance

Playbook:
---
- hosts: cent
  gather_facts
: no
  tasks
:
 
- name: Gather list of ifcfg-* files
    find
:
      paths
: "/etc/sysconfig/network-scripts"
   
register: net_files

 
- name: DEBUG INFO
    debug
:
      msg
: "{{ net_files.stdout_lines }}"
      verbosity
: 3



Output:
# ansible-playbook test.yml

PLAY
[cent] ******************************************************************************************************************************************************************************************************************************

TASK
[Gather list of ifcfg-* files] ******************************************************************************************************************************************************************************************************
ok
: [cent7]

TASK
[DEBUG INFO] ************************************************************************************************************************************************************************************************************************
fatal
: [cent7]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'dict object' has no attribute 'stdout_lines'\n\nThe error appears to have been in '/etc/ansible/playbooks/dns/test.yml': line 10, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n  - name: DEBUG INFO\n    ^ here\n"}

PLAY RECAP
*******************************************************************************************************************************************************************************************************************************
cent7                      
: ok=1    changed=0    unreachable=0    failed=1




Kai Stian Olstad

unread,
Aug 24, 2017, 6:51:12 PM8/24/17
to ansible...@googlegroups.com
On fredag 25. august 2017 00.30.16 CEST John Harmon wrote:
> Side question: Where can I find a list of debug output types for my vars
> (ie. stdout, stdout_lines, etc)?

Each module return different ting, best is to check documentation or just run

- debug: var=<variable name in register>


> Thanks in advance
>
> test.yml
> ---
> - hosts: cent
> gather_facts: no
> tasks:
> - name: Gather list of ifcfg-* files
> find:
> paths: "/etc/sysconfig/network-scripts"
> register: net_files
>
> - name: DEBUG INFO
> debug:
> msg: "{{ net_files.stdout_lines }}"
> verbosity: 3

If you check the documentation
https://docs.ansible.com/ansible/latest/find_module.html#return-values

you'll see find only return files, examined and matched, not stdout_lines.

So changes it to "{{ net_files.files }}"

You could have check the content of the variable with

- debug: var=net_files


--
Kai Stian Olstad

John Harmon

unread,
Aug 24, 2017, 6:57:11 PM8/24/17
to Ansible Project
Perfect.  Thank you.  That was the information I needed.  I saw the return values earlier in the documentation, but I assumed I didn't understand it.  Thx for the debug info too, that will help me in the future.
Reply all
Reply to author
Forward
0 new messages