github.com/aclaygray/packer@v1.3.2/examples/ansible/connection-plugin/2.5.x/packer.py (about)

     1  from __future__ import (absolute_import, division, print_function)
     2  __metaclass__ = type
     3  
     4  from ansible.plugins.connection.ssh import Connection as SSHConnection
     5  
     6  DOCUMENTATION = '''
     7      connection: packer
     8      short_description: ssh based connections for powershell via packer
     9      description:
    10          - This connection plugin allows ansible to communicate to the target packer machines via ssh based connections for powershell.
    11      author: Packer Community
    12      version_added: na
    13      options:
    14        host:
    15            description: Hostname/ip to connect to.
    16            default: inventory_hostname
    17            vars:
    18                 - name: ansible_host
    19                 - name: ansible_ssh_host
    20        host_key_checking:
    21            description: Determines if ssh should check host keys
    22            type: boolean
    23            ini:
    24                - section: defaults
    25                  key: 'host_key_checking'
    26                - section: ssh_connection
    27                  key: 'host_key_checking'
    28                  version_added: '2.5'
    29            env:
    30                - name: ANSIBLE_HOST_KEY_CHECKING
    31                - name: ANSIBLE_SSH_HOST_KEY_CHECKING
    32                  version_added: '2.5'
    33            vars:
    34                - name: ansible_host_key_checking
    35                  version_added: '2.5'
    36                - name: ansible_ssh_host_key_checking
    37                  version_added: '2.5'
    38        password:
    39            description: Authentication password for the C(remote_user). Can be supplied as CLI option.
    40            vars:
    41                - name: ansible_password
    42                - name: ansible_ssh_pass
    43        ssh_args:
    44            description: Arguments to pass to all ssh cli tools
    45            default: '-C -o ControlMaster=auto -o ControlPersist=60s'
    46            ini:
    47                - section: 'ssh_connection'
    48                  key: 'ssh_args'
    49            env:
    50                - name: ANSIBLE_SSH_ARGS
    51        ssh_common_args:
    52            description: Common extra args for all ssh CLI tools
    53            vars:
    54                - name: ansible_ssh_common_args
    55        ssh_executable:
    56            default: ssh
    57            description:
    58              - This defines the location of the ssh binary. It defaults to `ssh` which will use the first ssh binary available in $PATH.
    59              - This option is usually not required, it might be useful when access to system ssh is restricted,
    60                or when using ssh wrappers to connect to remote hosts.
    61            env: [{name: ANSIBLE_SSH_EXECUTABLE}]
    62            ini:
    63            - {key: ssh_executable, section: ssh_connection}
    64            yaml: {key: ssh_connection.ssh_executable}
    65            #const: ANSIBLE_SSH_EXECUTABLE
    66            version_added: "2.2"
    67        scp_extra_args:
    68            description: Extra exclusive to the 'scp' CLI
    69            vars:
    70                - name: ansible_scp_extra_args
    71        sftp_extra_args:
    72            description: Extra exclusive to the 'sftp' CLI
    73            vars:
    74                - name: ansible_sftp_extra_args
    75        ssh_extra_args:
    76            description: Extra exclusive to the 'ssh' CLI
    77            vars:
    78                - name: ansible_ssh_extra_args
    79        retries:
    80            # constant: ANSIBLE_SSH_RETRIES
    81            description: Number of attempts to connect.
    82            default: 3
    83            type: integer
    84            env:
    85              - name: ANSIBLE_SSH_RETRIES
    86            ini:
    87              - section: connection
    88                key: retries
    89              - section: ssh_connection
    90                key: retries
    91        port:
    92            description: Remote port to connect to.
    93            type: int
    94            default: 22
    95            ini:
    96              - section: defaults
    97                key: remote_port
    98            env:
    99              - name: ANSIBLE_REMOTE_PORT
   100            vars:
   101              - name: ansible_port
   102              - name: ansible_ssh_port
   103        remote_user:
   104            description:
   105                - User name with which to login to the remote server, normally set by the remote_user keyword.
   106                - If no user is supplied, Ansible will let the ssh client binary choose the user as it normally
   107            ini:
   108              - section: defaults
   109                key: remote_user
   110            env:
   111              - name: ANSIBLE_REMOTE_USER
   112            vars:
   113              - name: ansible_user
   114              - name: ansible_ssh_user
   115        pipelining:
   116            default: ANSIBLE_PIPELINING
   117            description:
   118              - Pipelining reduces the number of SSH operations required to execute a module on the remote server,
   119                by executing many Ansible modules without actual file transfer.
   120              - This can result in a very significant performance improvement when enabled.
   121              - However this conflicts with privilege escalation (become).
   122                For example, when using sudo operations you must first disable 'requiretty' in the sudoers file for the target hosts,
   123                which is why this feature is disabled by default.
   124            env:
   125              - name: ANSIBLE_PIPELINING
   126              #- name: ANSIBLE_SSH_PIPELINING
   127            ini:
   128              - section: defaults
   129                key: pipelining
   130              #- section: ssh_connection
   131              #  key: pipelining
   132            type: boolean
   133            vars:
   134              - name: ansible_pipelining
   135              - name: ansible_ssh_pipelining
   136        private_key_file:
   137            description:
   138                - Path to private key file to use for authentication
   139            ini:
   140              - section: defaults
   141                key: private_key_file
   142            env:
   143              - name: ANSIBLE_PRIVATE_KEY_FILE
   144            vars:
   145              - name: ansible_private_key_file
   146              - name: ansible_ssh_private_key_file
   147        control_path:
   148          default: null
   149          description:
   150            - This is the location to save ssh's ControlPath sockets, it uses ssh's variable substitution.
   151            - Since 2.3, if null, ansible will generate a unique hash. Use `%(directory)s` to indicate where to use the control dir path setting.
   152          env:
   153            - name: ANSIBLE_SSH_CONTROL_PATH
   154          ini:
   155            - key: control_path
   156              section: ssh_connection
   157        control_path_dir:
   158          default: ~/.ansible/cp
   159          description:
   160            - This sets the directory to use for ssh control path if the control path setting is null.
   161            - Also, provides the `%(directory)s` variable for the control path setting.
   162          env:
   163            - name: ANSIBLE_SSH_CONTROL_PATH_DIR
   164          ini:
   165            - section: ssh_connection
   166              key: control_path_dir
   167        sftp_batch_mode:
   168          default: True
   169          description: 'TODO: write it'
   170          env: [{name: ANSIBLE_SFTP_BATCH_MODE}]
   171          ini:
   172          - {key: sftp_batch_mode, section: ssh_connection}
   173          type: boolean
   174        scp_if_ssh:
   175          default: smart
   176          description:
   177            - "Prefered method to use when transfering files over ssh"
   178            - When set to smart, Ansible will try them until one succeeds or they all fail
   179            - If set to True, it will force 'scp', if False it will use 'sftp'
   180          env: [{name: ANSIBLE_SCP_IF_SSH}]
   181          ini:
   182          - {key: scp_if_ssh, section: ssh_connection}
   183        use_tty:
   184          version_added: '2.5'
   185          default: True
   186          description: add -tt to ssh commands to force tty allocation
   187          env: [{name: ANSIBLE_SSH_USETTY}]
   188          ini:
   189          - {key: usetty, section: ssh_connection}
   190          type: boolean
   191          yaml: {key: connection.usetty}
   192  '''
   193  
   194  class Connection(SSHConnection):
   195      ''' ssh based connections for powershell via packer'''
   196  
   197      transport = 'packer'
   198      has_pipelining = True
   199      become_methods = []
   200      allow_executable = False
   201      module_implementation_preferences = ('.ps1', '')
   202  
   203      def __init__(self, *args, **kwargs):
   204          super(Connection, self).__init__(*args, **kwargs)