summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/connection_delegation
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/connection_delegation')
-rw-r--r--test/integration/targets/connection_delegation/action_plugins/delegation_action.py12
-rw-r--r--test/integration/targets/connection_delegation/aliases6
-rw-r--r--test/integration/targets/connection_delegation/connection_plugins/delegation_connection.py45
-rw-r--r--test/integration/targets/connection_delegation/inventory.ini1
-rwxr-xr-xtest/integration/targets/connection_delegation/runme.sh9
-rw-r--r--test/integration/targets/connection_delegation/test.yml23
6 files changed, 96 insertions, 0 deletions
diff --git a/test/integration/targets/connection_delegation/action_plugins/delegation_action.py b/test/integration/targets/connection_delegation/action_plugins/delegation_action.py
new file mode 100644
index 0000000..9d419e7
--- /dev/null
+++ b/test/integration/targets/connection_delegation/action_plugins/delegation_action.py
@@ -0,0 +1,12 @@
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+from ansible.plugins.action import ActionBase
+
+
+class ActionModule(ActionBase):
+
+ def run(self, tmp=None, task_vars=None):
+ return {
+ 'remote_password': self._connection.get_option('remote_password'),
+ }
diff --git a/test/integration/targets/connection_delegation/aliases b/test/integration/targets/connection_delegation/aliases
new file mode 100644
index 0000000..6c96566
--- /dev/null
+++ b/test/integration/targets/connection_delegation/aliases
@@ -0,0 +1,6 @@
+shippable/posix/group3
+context/controller
+skip/freebsd # No sshpass
+skip/osx # No sshpass
+skip/macos # No sshpass
+skip/rhel # No sshpass
diff --git a/test/integration/targets/connection_delegation/connection_plugins/delegation_connection.py b/test/integration/targets/connection_delegation/connection_plugins/delegation_connection.py
new file mode 100644
index 0000000..f61846c
--- /dev/null
+++ b/test/integration/targets/connection_delegation/connection_plugins/delegation_connection.py
@@ -0,0 +1,45 @@
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+DOCUMENTATION = """
+author: Ansible Core Team
+connection: delegation_connection
+short_description: Test connection for delegated host check
+description:
+- Some further description that you don't care about.
+options:
+ remote_password:
+ description: The remote password
+ type: str
+ vars:
+ - name: ansible_password
+ # Tests that an aliased key gets the -k option which hardcodes the value to password
+ aliases:
+ - password
+"""
+
+from ansible.plugins.connection import ConnectionBase
+
+
+class Connection(ConnectionBase):
+
+ transport = 'delegation_connection'
+ has_pipelining = True
+
+ def __init__(self, *args, **kwargs):
+ super(Connection, self).__init__(*args, **kwargs)
+
+ def _connect(self):
+ super(Connection, self)._connect()
+
+ def exec_command(self, cmd, in_data=None, sudoable=True):
+ super(Connection, self).exec_command(cmd, in_data, sudoable)
+
+ def put_file(self, in_path, out_path):
+ super(Connection, self).put_file(in_path, out_path)
+
+ def fetch_file(self, in_path, out_path):
+ super(Connection, self).fetch_file(in_path, out_path)
+
+ def close(self):
+ super(Connection, self).close()
diff --git a/test/integration/targets/connection_delegation/inventory.ini b/test/integration/targets/connection_delegation/inventory.ini
new file mode 100644
index 0000000..e7f846d
--- /dev/null
+++ b/test/integration/targets/connection_delegation/inventory.ini
@@ -0,0 +1 @@
+my_host ansible_host=127.0.0.1 ansible_connection=delegation_connection
diff --git a/test/integration/targets/connection_delegation/runme.sh b/test/integration/targets/connection_delegation/runme.sh
new file mode 100755
index 0000000..4d50724
--- /dev/null
+++ b/test/integration/targets/connection_delegation/runme.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+
+set -ux
+
+echo "Checking if sshpass is present"
+command -v sshpass 2>&1 || exit 0
+echo "sshpass is present, continuing with test"
+
+sshpass -p my_password ansible-playbook -i inventory.ini test.yml -k "$@"
diff --git a/test/integration/targets/connection_delegation/test.yml b/test/integration/targets/connection_delegation/test.yml
new file mode 100644
index 0000000..678bef5
--- /dev/null
+++ b/test/integration/targets/connection_delegation/test.yml
@@ -0,0 +1,23 @@
+---
+- hosts: localhost
+ gather_facts: no
+ tasks:
+ - name: test connection receives -k from play_context when delegating
+ delegation_action:
+ delegate_to: my_host
+ register: result
+
+ - assert:
+ that:
+ - result.remote_password == 'my_password'
+
+ - name: ensure vars set for that host take precedence over -k
+ delegation_action:
+ delegate_to: my_host
+ vars:
+ ansible_password: other_password
+ register: result
+
+ - assert:
+ that:
+ - result.remote_password == 'other_password'