Is there any Alternative of command/shell module

18 views
Skip to first unread message

Rakesh Parida

unread,
Jul 19, 2019, 5:40:14 AM7/19/19
to Ansible Project
I prepared a playbook as follows:
---
- hosts: localhost
  vars:
    directory_name: /root/raka-tests/
  tasks:
  - name: List the Contents of dir
    command: ls -lrt {{ directory_name }}
    register: files
  - debug:
      msg: "{{ files.stdout_lines}}"

o/p:
TASK [debug] ***********************************************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        "total 80",
        "-rw-r--r--. 1 root root  945 Jul 12 05:53 rel.yml",
        "-rw-r--r--. 1 root root  280 Jul 12 06:19 playbook.yaml",
        "-rw-r--r--. 1 root root  237 Jul 12 09:00 rakesh.yml",
        "-rw-r--r--. 1 root root  179 Jul 15 05:40 playbook2.yml",
        "-rw-r--r--. 1 root root  376 Jul 15 05:49 playbook3.yml",
        "-rw-r--r--. 1 root root  376 Jul 15 05:52 playbook4.yml",

I dont want to use command/shell  module. Is there any module which will show me the list sof contents of adirectory

Dick Visser

unread,
Jul 19, 2019, 6:18:36 AM7/19/19
to ansible...@googlegroups.com
It's not clear what you are trying to do.
Depending on your use case you could either use fileglob:
https://docs.ansible.com/ansible/latest/plugins/lookup/fileglob.html
Or if you need to filter on specific permissions etc, use the find
module: https://docs.ansible.com/ansible/latest/modules/find_module.html


Dick
> --
> 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 ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/cd9ca004-a446-4900-9fe1-180cd76a22eb%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

P.Co...@bham.ac.uk

unread,
Jul 19, 2019, 6:24:15 AM7/19/19
to ansible...@googlegroups.com

Not really clear why command or shell doesn’t meet your needs but take a look at find, file or stat perhaps. See full list of modules below:

 

https://docs.ansible.com/ansible/latest/modules/list_of_all_modules.html

 

Regards

Phil

--

Reply all
Reply to author
Forward
0 new messages