title: become_user with command sudo rootsh -i -u root , ansible
body: <p>I have a question about how to run commands as root. The playbook is really simple, create a folder and after that change the owner and group</p>
  
  <pre class="lang-sh prettyprint-override"><code>  - name: install-home-db | Create scatch directory only if it is needed
      become: yes
      file:
        path: "{{ scratch_patch }}/oracle_{{ db_version | replace('.', '_') }}"
        mode: 775
        owner: "{{ oracle_user }}"
        group: "{{ oracle_group }}"
        state: directory
      register: oracle_medias
  </code></pre>
  
  <p>The folder is created whitout problem, the problem comes when it wants to setup the user and group</p>
  
  <p>In remote server I do not have permissions to run any sudo command, but I can become root user if launch command </p>
  
  <pre class="lang-sh prettyprint-override"><code>sudo rootsh -i -u root
  </code></pre>
  
  <p>Please notice that I only can become root if use this exact command, if I run only</p>
  
  <pre class="lang-sh prettyprint-override"><code>sudo rootsh -u root
  </code></pre>
  
  <p>It does not work and returns </p>
  
  <pre class="lang-sh prettyprint-override"><code>Sorry, user fcruzloz is not allowed to execute '/usr/bin/rootsh -u root' as root on dcplnx22121944.
  </code></pre>
  
  <p>So how could I run command using root user?
  I have tried setting below paramters in ansible.cfg</p>
  
  <pre class="lang-sh prettyprint-override"><code>[defaults]
  host_key_checking             = false
  # ask_pass                    = True
  inventory                     = inventory/hosts
  allow_world_readable_tmpfiles = true
  remote_user                   = fcruzloz
  executable                    = /bin/bash
  timeout                       = 50
  
  
  [privilege_escalation]
  become_exe                    = sudo rootsh
  become_user                   = root
  become_flags                  = -i
  </code></pre>
  
  <p>But it is still failing because permissions, when running ansible command with -vvv, I think the culprit line is below one</p>
  
  <pre class="lang-sh prettyprint-override"><code>&lt;2a00:da9:2:21ca:111:0:427:1&gt; SSH: EXEC ssh -o ControlMaster=no -o ServerAliveInterval=50 -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="fcruzloz"' -o ConnectTimeout=50 -tt 2a00:da9:2:21ca:111:0:427:1 '/bin/bash -c '"'"'sudo rootsh -i  -u root /bin/bash -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-eybzqcaxfeytghcwykijkpeqdlpzphdq ; /usr/bin/python /home/admin/fcruzloz/.ansible/tmp/ansible-tmp-1570663425.52-9612101629719/AnsiballZ_file.py'"'"'"'"'"'"'"'"' &amp;&amp; sleep 0'"'"''
  Escalation succeeded
  </code></pre>
  
  <p>And that makes sense when checking errors in /var/log/messages</p>
  
  <pre class="lang-sh prettyprint-override"><code>2019-10-09T16:24:15.472458-07:00 dcplnx22121944 sudo: fcruzloz : command not allowed ; TTY=pts/14 ; PWD=/home/admin/fcruzloz ; USER=root ; COMMAND=/usr/bin/rootsh -i -u root /bin/bash -c echo BECOME-SUCCESS-eybzqcaxfeytghcwykijkpeqdlpzphdq ; /usr/bin/python /home/admin/fcruzloz/.ansible/tmp/ansible-tmp-1570663425.52-9612101629719/AnsiballZ_file.py
  2019-10-09T16:24:15.625928-07:00 dcplnx22121944 sshd[16027]: Connection closed by 2a00:da9:ffa0:8601::2
  </code></pre>
  
  <p>If I run the ansible command directly in server, I mean something like below (It is not exactly same command), it fails</p>
  
  <pre class="lang-sh prettyprint-override"><code>fcruzloz@dcplnx22121944:/home/admin/fcruzloz&gt; sudo rootsh -i  -u root /bin/bash -c 'echo test'
  Sorry, user fcruzloz is not allowed to execute '/usr/bin/rootsh -i -u root /bin/bash -c echo test' as root on dcplnx22121944.
  </code></pre>
  
  <p>I guess I need to do something like redirect the command to the new root shell but I could not do this, I tried with openvt but I did not get it</p>
  
  <p>So do you have some idea?
  Thanks a lot in advance for your help</p>
  
  <p>My control maching is below linux flavor</p>
  
  <pre class="lang-sh prettyprint-override"><code>NAME="SLES"
  VERSION="12-SP2"
  VERSION_ID="12.2"
  PRETTY_NAME="SUSE Linux Enterprise Server 12 SP2"
  ID="sles"
  ANSI_COLOR="0;32"
  CPE_NAME="cpe:/o:suse:sles:12:sp2"
  SUSE Linux Enterprise Server 12 (x86_64)
  VERSION = 12
  PATCHLEVEL = 2
  </code></pre>