| 1 |
# Copyright 2019, David Wilson |
| 2 |
# |
| 3 |
# Redistribution and use in source and binary forms, with or without |
| 4 |
# modification, are permitted provided that the following conditions are met: |
| 5 |
# |
| 6 |
# 1. Redistributions of source code must retain the above copyright notice, |
| 7 |
# this list of conditions and the following disclaimer. |
| 8 |
# |
| 9 |
# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 10 |
# this list of conditions and the following disclaimer in the documentation |
| 11 |
# and/or other materials provided with the distribution. |
| 12 |
# |
| 13 |
# 3. Neither the name of the copyright holder nor the names of its contributors |
| 14 |
# may be used to endorse or promote products derived from this software without |
| 15 |
# specific prior written permission. |
| 16 |
# |
| 17 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 21 |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 |
# POSSIBILITY OF SUCH DAMAGE. |
| 28 |
|
| 29 |
""" |
| 30 |
Fetch the connection configuration stack that would be used to connect to a |
| 31 |
target, without actually connecting to it. |
| 32 |
""" |
| 33 |
|
| 34 |
from __future__ import absolute_import, division, print_function |
| 35 |
from __future__ import unicode_literals |
| 36 |
__metaclass__ = type |
| 37 |
|
| 38 |
import ansible_mitogen.connection |
| 39 |
|
| 40 |
from ansible.plugins.action import ActionBase |
| 41 |
|
| 42 |
|
| 43 |
class ActionModule(ActionBase): |
| 44 |
def run(self, tmp=None, task_vars=None): |
| 45 |
if not isinstance(self._connection, |
| 46 |
ansible_mitogen.connection.Connection): |
| 47 |
return { |
| 48 |
'skipped': True, |
| 49 |
} |
| 50 |
|
| 51 |
_, stack = self._connection._build_stack() |
| 52 |
return { |
| 53 |
'changed': True, |
| 54 |
'result': stack, |
| 55 |
'_ansible_verbose_always': True, |
| 56 |
# for ansible < 2.8, we'll default to /usr/bin/python like before |
| 57 |
'discovered_interpreter': self._connection._action._discovered_interpreter |
| 58 |
} |