Directory is not getting created using file module

**Hello Community, I am trying to create directory using file module and it is not working as expected **
My playbook as follows

- name: creating facts directory
  ansible.builtin.file:
    path: /tmp/saravana/facts
    state: directory
    mode: '0755'
    owner: root
    group: root
  become: yes

And the output of it as follows,

changed: [xxxx-xxxx.xxxx.com] => {
    "changed": true,
    "diff": {
        "after": {
            "path": "/tmp/saravana/facts",
            "state": "directory"
        },
        "before": {
            "path": "/tmp/saravana/facts",
            "state": "absent"
        }
    },
    "invocation": {
        "module_args": {
            "_diff_peek": null,
            "_original_basename": null,
            "access_time": null,
            "access_time_format": "%Y%m%d%H%M.%S",
            "attributes": null,
            "follow": true,
            "force": false,
            "group": "root",
            "mode": "0755",
            "modification_time": null,
            "modification_time_format": "%Y%m%d%H%M.…

Can you please check what is the issue here ?

Thanks and Regards
Saravana Selvaraj

@SaravanaSelvaraj Hello!

What are you expected and actual result?

Was the directory actually created or not?

Hello @akira6592 , sorry for the missout ! Yes the directory is not getting created . How can I troubleshoot this issue ?

Best regards
Saravana Selvaraj

Which errors are you seeing?
How are you invoking your playbook?
Are you verifying existence / non-existance of the directory on the correct machine?

1 Like

Hello @jpmens , I don’t see any errors and I can see the successful output.

changed: [XXXX.com] => {
    "changed": true,
    "diff": {
        "after": {
            "path": "/tmp/saravana/facts",
            "state": "directory"
        },
        "before": {
            "path": "/tmp/saravana/facts",
            "state": "absent"
        }
    },
  1. I am invoking the playbook using AWX.
  2. Yes I am verifying on the correct machine.

Is there anything else on your playbook ? Perhaps a system reboot after that (in which case /tmp might be emptied) ? What makes you say directory isn’t there ? How did you check ?

Given the elements you provided, I’m also wondering if you are indeed checking on correct machine. Perhaps try to create your directory somewhere else, see how it goes, or move it / rename it after, put something in there then fetching it, etc… (using Ansible) to ensure it’s still there all along your playbook execution.

Maybe run your playbook using ansible-playbook binary instead of running it through AWX, just in case there might be another cleanup process, chained job or else involved in this ?

1 Like