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