# shell: umask 0022 not working

**URL:** <https://forum.ansible.com/t/shell-umask-0022-not-working/31943>\
**Category:** Ansible Project\
**Created:** [January 9, 2020, 5:32pm UTC](https://forum.ansible.com/t/shell-umask-0022-not-working/31943 "2020-01-09T17:32:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Masudur\_Rahman](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@Masudur\_Rahman](https://forum.ansible.com/u/Masudur_Rahman)\
**Post date:** [January 9, 2020, 5:32pm UTC](https://forum.ansible.com/t/shell-umask-0022-not-working/31943/1 "2020-01-09T17:32:59Z")

</div>

Can anyone help me to set umask 0022.  
I’m always getting 0027 after executing playbook run.

Error:

```auto
fatal: [********]: FAILED! => {"changed": true, "cmd": "./installer-binary.run --mode text --disable_glibcxx_version_check 1", "delta": "0:00:30.128584", "end": "2020-01-08 18:53:55.234070", "msg": "command exceeded timeout", "rc": null, "start": "2020-01-08 18:53:25.105486", "stdout": "\r\r\nError: There has been an error.\r\r\nThe installation has detected that the current umask is set to permissions of \r\r\n0027, the installation is now exiting. You should modify your umask to at least \r\r\n0022 before launching the installer. After the installation has completed, reset \r\r\nthe umask permissions to your original values.\r\r\nPress [Enter] to continue:", "stdout_lines": ["", "", "Error: There has been an error.", "", "The installation has detected that the current umask is set to permissions of ", "", "0027, the installation is now exiting. You should modify your umask to at least ", "", "0022 before launching the installer. After the installation has completed, reset ", "", "the umask permissions to your original values.", "", "Press [Enter] to continue:"]}

```

here’s my task(s):

```auto
      - name: Change Umask to 0022 to make installer working
        shell: umask 0022 && umask

      - name: Generic question with multiple different responses
        expect:
          echo: yes
          command: ./{{ version }} --mode text --disable_glibcxx_version_check 1
          chdir: /home/app/installers/
          responses:
            Question:
              'Please choose an option': '2'
              '\[\/opt\/app\]': '\n'
              'Backup Directory \[\/opt\/app\]': '/home/app/backup/'
              'Password ': 'Password'
              'Do you want to continue\? \[Y\/n\]': 'y'

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 9, 2020, 5:37pm UTC](https://forum.ansible.com/t/shell-umask-0022-not-working/31943/2 "2020-01-09T17:37:53Z")

</div>

Ansible tasks normally do NOT share the same session, so setting umask  
for the session in one task will not affect subsequent tasks, you need  
to modify umask in a persistent manner for all tasks to be affected,  
Normally you can affect the environment in a consistent way across  
tasks by using the `enviornment` keyword at play/block/role/task  
levels, sadly umask is not configurable way.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 9, 2020, 6:11pm UTC](https://forum.ansible.com/t/shell-umask-0022-not-working/31943/3 "2020-01-09T18:11:41Z")

</div>

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Change Umask to 0022 to make installer working  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: umask 0022 && umask
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Generic question with multiple different responses  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expect:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo: yes  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: ./{{ version }} --mode text --disable\_glibcxx\_version\_check 1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chdir: /home/app/installers/

As Brian mention, thing set it one task is not propagated to the next.  
umask is a built in shell feature and the expect module is Python with no way of setting umask.  
So you have a least two alternatives, setting the umask before running ansible-playbook or use bash/sh to execute the command in expect.

&nbsp;&nbsp;&nbsp;command: bash -c "umask 0022; ./{{ version }} --mode text --disable\_glibcxx\_version\_check 1"

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;responses:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Question:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Please choose an option': '2'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'\[\/opt\/app\]': '\n'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Backup Directory \[\/opt\/app\]': '/home/app/backup/'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Password ': 'Password'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Do you want to continue\? \[Y\/n\]': 'y'

This will not work, question is the actual key in you dict and not a parameter you can use with expect.  
Correct code would be:

&nbsp;&nbsp;&nbsp;responses:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Please choose an option': '2'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'\[\/opt\/app\]': '\n'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Backup Directory \[\/opt\/app\]': '/home/app/backup/'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Password ': 'Password'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Do you want to continue\? \[Y\/n\]': 'y'

---

<div class="post-metadata">

**Author:** ![Masudur\_Rahman](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@Masudur\_Rahman](https://forum.ansible.com/u/Masudur_Rahman)\
**Post date:** [January 11, 2020, 7:35am UTC](https://forum.ansible.com/t/shell-umask-0022-not-working/31943/4 "2020-01-11T07:35:38Z")

</div>

Thank you very much. It worked like a charm.
