Bug 1728612

Summary: Include Ansible become_method or make it inherit from rex settings
Product: Red Hat Satellite Reporter: Kenny Tordeurs <ktordeur>
Component: Ansible - Configuration ManagementAssignee: Nagoor Shaik <nshaik>
Status: CLOSED ERRATA QA Contact: Lukas Pramuk <lpramuk>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.5.0CC: bkearney, dvoss, egolov, mcorr, mkalyat, mmccune, pcreech, spetrosi, trichard, zhunting
Target Milestone: 6.7.0Keywords: Triaged
Target Release: Unused   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: tfm-rubygem-foreman_ansible-3.0.8.1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-04-14 13:24:51 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Kenny Tordeurs 2019-07-10 09:14:32 UTC
Description of problem:
Currently Ansible always uses sudo become_method instead of using the specified 'Effective User Method' it does inherit other settings like 'ssh user' and 'ssh password' so one would expect it would also do this for the become_method.

Version-Release number of selected component (if applicable):
Satellite 6.5

How reproducible:
100%

Steps to Reproduce:
1. Administer -> Settings -> Remote execution settings -> Effective User Method -> su
2. Run ansible playbook
3. Will default to sudo method

Actual results:
~~~
Jul 10 08:44:38 ktordeur-test-ansible sshd[24644]: Accepted password for local from 192.168.140.2 port 44284 ssh2
Jul 10 08:44:38 ktordeur-test-ansible sshd[24644]: pam_unix(sshd:session): session opened for user local by (uid=0)
Jul 10 08:44:39 ktordeur-test-ansible unix_chkpwd[24730]: password check failed for user (local)
Jul 10 08:44:39 ktordeur-test-ansible sudo: pam_unix(sudo:auth): authentication failure; logname=local uid=1000 euid=0 tty=/dev/pts/1 ruser=local rhost=  user=local
Jul 10 08:44:41 ktordeur-test-ansible sudo: pam_unix(sudo:auth): conversation failed
Jul 10 08:44:41 ktordeur-test-ansible sudo: pam_unix(sudo:auth): auth could not identify password for [local]
Jul 10 08:44:44 ktordeur-test-ansible sudo:   local : user NOT in sudoers ; TTY=pts/1 ; PWD=/home/local ; USER=root ; COMMAND=/bin/sh -c echo BECOME-SUCCESS-nxajxxxwohzbndgcgikajxfdvpmaqeov; /usr/bin/python /home/local/.ansible/tmp/ansible-tmp-1562748279.11-12389537057591/setup.py
~~~

Expected results:
Use the su method

Additional info:

Comment 4 Bryan Kearney 2019-08-08 12:07:06 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue https://projects.theforeman.org/issues/26850 has been resolved.

Comment 5 Lukas Pramuk 2019-10-07 16:41:03 UTC
FailedQA.

@Satellite 6.6.0 Snap22
tfm-rubygem-foreman_ansible-3.0.7.1-1.el7sat.noarch

# find / -path *app/services/foreman_ansible/inventory_creator.rb
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_ansible-3.0.7.1/app/services/foreman_ansible/inventory_creator.rb

# grep ansible_become_method /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_ansible-3.0.7.1/app/services/foreman_ansible/inventory_creator.rb
<empty>

>>> the fix is not present

Comment 6 Patrick Creech 2019-10-07 17:48:39 UTC
looking over the v3.0.7 tag in foreman_ansible, I do not see the attached fix.  It appears it did not make it into that release.

Comment 8 Lukas Pramuk 2020-02-04 13:54:15 UTC
VERIFIED.

@satellite-6.7.0-5.beta.el7sat.noarch
tfm-rubygem-foreman_ansible-4.0.3-1.el7sat.noarch

by the following manual reproducer:

1. Run Ansible Command job with following command:
ps -f $(ps -f $(ps -f $(ps -f $$ | awk 'NR>1{print $3}') | awk 'NR>1{print $3}') | awk 'NR>1{print $3}')

2. Check the output of the job
"stdout_lines": [
        "UID        PID  PPID  C STIME TTY      STAT   TIME CMD", 
        "root     23891 23876  1 13:09 pts/1    S+     0:00 sudo -H -S -p [sudo via ansible, key=bjewyccppqwazaqhkapkmopxvnrnrdea] password: -u test /bin/sh -c echo BECOME-SUCCESS-bjewyccppqwazaqhkapkmopxvnrnrdea ; /usr/bin/python /var/tmp/ansible-tmp-1580407876.01-46452950106097/AnsiballZ_command.py"
]

>>> by default "sudo" method is used

3. Change the method to "su" in the settings:
Administer -> Settings -> Remote execution settings -> Effective User Method -> su

4. Run Ansible Command job with the same command:
ps -f $(ps -f $(ps -f $(ps -f $$ | awk 'NR>1{print $3}') | awk 'NR>1{print $3}') | awk 'NR>1{print $3}')

5. Check the output of the job
"stdout_lines": [
        "UID        PID  PPID  C STIME TTY      STAT   TIME CMD", 
        "root     23579 23564  1 13:09 pts/1    S+     0:00 su test -c /bin/sh -c 'echo BECOME-SUCCESS-rkdzercgvekzoxetgbxnyqwajzsgmxih ; /usr/bin/python /var/tmp/ansible-tmp-1580407930.12-1211950403156/AnsiballZ_command.py'"
]

>>> "su" method is used as Ansible REX now inherits the setting from SSH REX

Comment 13 errata-xmlrpc 2020-04-14 13:24:51 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:1454