summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/cli
diff options
context:
space:
mode:
authorRick Elrod <rick@elrod.me>2020-05-22 15:34:26 +0200
committerGitHub <noreply@github.com>2020-05-22 15:34:26 +0200
commitfe9696be525d4ef3177decda6919206492977582 (patch)
tree81a79d5d30fde0f78a56a171124fe3abf27772ec /test/integration/targets/cli
parentfix delegated interpreter discovery (#69604) (diff)
downloadansible-fe9696be525d4ef3177decda6919206492977582.tar.xz
ansible-fe9696be525d4ef3177decda6919206492977582.zip
Fix `ansible -K` become_pass regression (#69629)
* Fix `ansible -K` become_pass regression Change: - This fixes a breaking change introduced in 2165f9ac40cf212891b11a75bd9b9b2f4f0b8dc3 Test Plan: - Local VM for now, with plans to add an integration test for -K going forward. Tickets: Refs #69244
Diffstat (limited to 'test/integration/targets/cli')
-rw-r--r--test/integration/targets/cli/aliases3
-rw-r--r--test/integration/targets/cli/setup.yml40
-rw-r--r--test/integration/targets/cli/test_k_and_K.py27
3 files changed, 69 insertions, 1 deletions
diff --git a/test/integration/targets/cli/aliases b/test/integration/targets/cli/aliases
index 6b71e884a1..a8816e110d 100644
--- a/test/integration/targets/cli/aliases
+++ b/test/integration/targets/cli/aliases
@@ -1,2 +1,5 @@
+destructive
+needs/root
+needs/ssh
needs/target/setup_pexpect
shippable/posix/group3
diff --git a/test/integration/targets/cli/setup.yml b/test/integration/targets/cli/setup.yml
index 9f6ab11741..901cfd14c0 100644
--- a/test/integration/targets/cli/setup.yml
+++ b/test/integration/targets/cli/setup.yml
@@ -1,4 +1,42 @@
- hosts: localhost
- gather_facts: no
+ gather_facts: yes
roles:
- setup_pexpect
+
+ tasks:
+ - name: Test ansible-playbook and ansible with -K
+ block:
+ - name: Create user to connect as
+ user:
+ name: cliuser1
+ shell: /bin/bash
+ groups: wheel
+ append: yes
+ password: "{{ 'secretpassword' | password_hash('sha512', 'mysecretsalt') }}"
+ - name: Create user to become
+ user:
+ name: cliuser2
+ shell: /bin/bash
+ password: "{{ 'secretpassword' | password_hash('sha512', 'mysecretsalt') }}"
+ # Sometimes this file doesn't get removed, and we need it gone to ssh
+ - name: Remove /run/nologin
+ file:
+ path: /run/nologin
+ state: absent
+ # Make Ansible run Python to run Ansible
+ - name: Run the test
+ shell: python test_k_and_K.py {{ ansible_python_interpreter }}
+ always:
+ - name: Remove users
+ user:
+ name: "{{ item }}"
+ state: absent
+ with_items:
+ - cliuser1
+ - cliuser2
+ # For now, we don't test this everywhere, because `user` works differently
+ # on some platforms, as does sudo/sudoers. On Fedora, we can just add
+ # the user to 'wheel' and things magically work.
+ # TODO: In theory, we should test this with all the different 'become'
+ # plugins in base.
+ when: ansible_distribution == 'Fedora'
diff --git a/test/integration/targets/cli/test_k_and_K.py b/test/integration/targets/cli/test_k_and_K.py
new file mode 100644
index 0000000000..f7077fba0a
--- /dev/null
+++ b/test/integration/targets/cli/test_k_and_K.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+# Make coding more python3-ish
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+import os
+import sys
+
+import pexpect
+
+os.environ['ANSIBLE_NOCOLOR'] = '1'
+
+out = pexpect.run(
+ 'ansible -c ssh -i localhost, -u cliuser1 -e ansible_python_interpreter={0} '
+ '-m command -a whoami -Kkb --become-user cliuser2 localhost'.format(sys.argv[1]),
+ events={
+ 'SSH password:': 'secretpassword\n',
+ 'BECOME password': 'secretpassword\n',
+ },
+ timeout=10
+)
+
+print(out)
+
+assert b'cliuser2' in out