shell: umask 0022 not working

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

Error:

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):

      - 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'

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.

       - 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/

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.

   command: bash -c "umask 0022; ./{{ version }} --mode text --disable_glibcxx_version_check 1"

           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'

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:

   responses:
     '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'

Thank you very much. It worked like a charm.