Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save privateip/bceb22eb0006d13040216e40faa591ff to your computer and use it in GitHub Desktop.
Save privateip/bceb22eb0006d13040216e40faa591ff to your computer and use it in GitHub Desktop.
#
# (c) 2016 Peter Sprygada <psprygada@ansible.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import re
import shlex
from ansible.plugins.connection.local import Connection as LocalConnection
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
class Connection(LocalConnection):
""" CLI based connection """
def _connect(self):
''' connect to the local host; nothing to do here '''
display.vvv(str(self._play_context.__dict__))
os.environ['ANSIBLE_NET_HOST'] = self._play_context.remote_addr
os.environ['ANSIBLE_NET_PORT'] = self._play_context.port or '22'
os.environ['ANSIBLE_NET_USERNAME'] = self._play_context.remote_user
if self._play_context.password:
os.environ['ANSIBLE_NET_PASSWORD'] = self._play_context.password
for arg in self.split(self._play_context.net_extra_args):
key, value = arg.split('=')
key = 'ANSIBLE_NET_%s' % key.upper()
os.environ[key] = str(value)
return super(Connection, self)._connect()
def split(self, value):
lex = shlex.shlex(value)
lex.quotes = '"'
lex.whitespace_split = True
lex.commenters = ''
return list(lex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment