-1

I have added to my playbook a small task that should change umask on my linux machine:

  - name: set umask to 0022
    shell: umask 0022

When running the playbook, I can see this task passes successfully:

changed: [myHostName] => {
"changed": true,
"cmd": "umask 0022",
"delta": "0:00:00.004660",
"end": "2020-08-04 16:28:44.153261",
"invocation": {
    "module_args": {
        "_raw_params": "umask 0022",
        "_uses_shell": true,
        "argv": null,
        "chdir": null,
        "creates": null,
        "executable": null,
        "removes": null,
        "stdin": null,
        "stdin_add_newline": true,
        "strip_empty_ends": true,
        "warn": true
    }
},
"rc": 0,
"start": "2020-08-04 16:28:44.148601",
"stderr": "",
"stderr_lines": [],
"stdout": "",
"stdout_lines": []
}

but After the playbook finishes, I check the umask and see that it was not changed at all:

-bash-4.2$ umask
0044

I also put a debug in my playbook right after the task I showed above, and the debug also shows that the umask was not changed.. Tried also with

become: yes

But got the same result..

When I do the command on my Linux manually, it will work:

-bash-4.2$ umask 0022
-bash-4.2$ umask
0022
Dharman
  • 30,962
  • 25
  • 85
  • 135
jrz
  • 1,213
  • 4
  • 20
  • 54

1 Answers1

1

Q: After the playbook finishes, I check the umask and see that it was not changed at all.

A: This is correct. Ansible isn't really doing things through the shell i.e. the changes live in this one session only.

Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
  • Hi, thanks for your answer. I know the changes live in the session only. That's why I mentioned that right after the task I added a debug that shows the umask. So when the playbook arrives at this debug, I should see umask is 0022 right? But I see umask 0044 i.e didn't change. – jrz Aug 04 '20 at 13:59
  • What this means is that the umask only changes for that session. Try `shell: umask 0022 && umask`. Then debug the `stdout`. To "set" the umask, it would be better to use `/etc/profile` (system-wide) or `~/.bashrc` (user-specific) – seshadri_c Aug 04 '20 at 15:46