Debian Codegraph @

test/integration/targets/delegate_to/connection_plugins/fakelocal.py

raw
1 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
2
3 from __future__ import annotations
4
5 DOCUMENTATION = """
6 connection: fakelocal
7 short_description: dont execute anything
8 description:
9 - This connection plugin just verifies parameters passed in
10 author: ansible (@core)
11 version_added: hysterical
12 options:
13 password:
14 description: Authentication password for the C(remote_user). Can be supplied as CLI option.
15 vars:
16 - name: ansible_password
17 remote_user:
18 description:
19 - User name with which to login to the remote server, normally set by the remote_user keyword.
20 ini:
21 - section: defaults
22 key: remote_user
23 vars:
24 - name: ansible_user
25 """
26
27 from ansible.errors import AnsibleConnectionFailure
28 from ansible.plugins.connection import ConnectionBase
29 from ansible.utils.display import Display
30
31 display = Display()
32
33
34 class Connection(ConnectionBase):
35 """ Local based connections """
36
37 transport = 'fakelocal'
38 has_pipelining = True
39
40 def __init__(self, *args, **kwargs):
41
42 super(Connection, self).__init__(*args, **kwargs)
43 self.cwd = None
44
45 def _connect(self):
46 """ verify """
47
48 if self.get_option('remote_user') == 'invaliduser' and self.get_option('password') == 'badpassword':
49 raise AnsibleConnectionFailure('Got invaliduser and badpassword')
50
51 if not self._connected:
52 display.vvv(u"ESTABLISH FAKELOCAL CONNECTION FOR USER: {0}".format(self._play_context.remote_user), host=self._play_context.remote_addr)
53 self._connected = True
54 return self
55
56 def exec_command(self, cmd, in_data=None, sudoable=True):
57 """ run a command on the local host """
58
59 super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
60
61 return 0, '{"msg": "ALL IS GOOD"}', ''
62
63 def put_file(self, in_path, out_path):
64 """ transfer a file from local to local """
65
66 super(Connection, self).put_file(in_path, out_path)
67
68 def fetch_file(self, in_path, out_path):
69 """ fetch a file from local to local -- for compatibility """
70
71 super(Connection, self).fetch_file(in_path, out_path)
72
73 def close(self):
74 """ terminate the connection; nothing to do here """
75 self._connected = False