- hosts: test
  remote_user: ec2-user
  sudo: yes
  tasks:
      #using the shell command because we need * expansion, otherwise if we 
know the exact directory we can use command module instead
      - name: list log directory to find main directory name
        find:
            paths: [ "/var/log/" ]
            patterns: "file-main*"
            file_type: directory
        register: out_directories

      - debug: var="{{ item }}"
        with_items: "{{ out_directories }}"

The output is

ansible-playbook -vv -i hosts -u ec2-user directory_cleanup.yml
Using /Users/ggao/Projects/ansible-playbooks/test/ansible.cfg as config file
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user 
and make sure become_method is 'sudo' (default).
This feature will be removed
in a future release. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.

PLAYBOOK: directory_cleanup.yml 
************************************************
1 plays in directory_cleanup.yml

PLAY [test] 
********************************************************************

TASK [setup] 
*******************************************************************
ok: [10.81.108.140]

TASK [list log directory to find wasabi main directory name] 
*******************
task path: 
/Users/ggao/Projects/ansible-playbooks/test/directory_cleanup.yml:8
ok: [10.81.108.140] => {"changed": false, "examined": 30, "files": 
[{"atime": 1478891483.1474261, "ctime": 1478891479.107535, "dev": 51713, 
"gid": 50002, "inode": 264540, "isblk": false, "ischr": false, "isdir": 
true, "isfifo": false, "isgid": false, "islnk": false, "isreg": false, 
"issock": false, "isuid": false, "mode": "0755", "mtime": 
1478891479.107535, "nlink": 2, "path": "/var/log/file-main-20161108022522", 
"rgrp": true, "roth": true, "rusr": true, "size": 4096, "uid": 50002, 
"wgrp": false, "woth": false, "wusr": true, "xgrp": true, "xoth": true, 
"xusr": true}], "matched": 1, "msg": ""}

TASK [debug] 
*******************************************************************
task path: 
/Users/ggao/Projects/ansible-playbooks/test/directory_cleanup.yml:16
ok: [10.81.108.140] => (item=files) => {
    "files": "VARIABLE IS NOT DEFINED!",
    "item": "files"
}
ok: [10.81.108.140] => (item=msg) => {
    "item": "msg",
    "msg": "VARIABLE IS NOT DEFINED!"
}
changed: [10.81.108.140] => (item=changed) => {
    "changed": "VARIABLE IS NOT DEFINED!",
    "item": "changed"
}
ok: [10.81.108.140] => (item=examined) => {
    "examined": "VARIABLE IS NOT DEFINED!",
    "item": "examined"
}
ok: [10.81.108.140] => (item=matched) => {
    "item": "matched",
    "matched": "VARIABLE IS NOT DEFINED!"
}

PLAY RECAP 
*********************************************************************
10.81.108.140              : ok=3    changed=1    unreachable=0    failed=0


using python 2.7 on ansible-playbook 2.2.0.0

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/daf304ff-4409-49aa-a687-48deb6e4f8c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to