github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/examples/ansible/connection-plugin/2.6.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            #const: ANSIBLE_SSH_EXECUTABLE
    65            version_added: "2.2"
    66        sftp_executable:
    67            default: sftp
    68            description:
    69              - This defines the location of the sftp binary. It defaults to ``sftp`` which will use the first binary available in $PATH.
    70            env: [{name: ANSIBLE_SFTP_EXECUTABLE}]
    71            ini:
    72            - {key: sftp_executable, section: ssh_connection}
    73            version_added: "2.6"
    74        scp_executable:
    75            default: scp
    76            description:
    77              - This defines the location of the scp binary. It defaults to `scp` which will use the first binary available in $PATH.
    78            env: [{name: ANSIBLE_SCP_EXECUTABLE}]
    79            ini:
    80            - {key: scp_executable, section: ssh_connection}
    81            version_added: "2.6"
    82        scp_extra_args:
    83            description: Extra exclusive to the ``scp`` CLI
    84            vars:
    85                - name: ansible_scp_extra_args
    86        sftp_extra_args:
    87            description: Extra exclusive to the ``sftp`` CLI
    88            vars:
    89                - name: ansible_sftp_extra_args
    90        ssh_extra_args:
    91            description: Extra exclusive to the 'ssh' CLI
    92            vars:
    93                - name: ansible_ssh_extra_args
    94        retries:
    95            # constant: ANSIBLE_SSH_RETRIES
    96            description: Number of attempts to connect.
    97            default: 3
    98            type: integer
    99            env:
   100              - name: ANSIBLE_SSH_RETRIES
   101            ini:
   102              - section: connection
   103                key: retries
   104              - section: ssh_connection
   105                key: retries
   106        port:
   107            description: Remote port to connect to.
   108            type: int
   109            default: 22
   110            ini:
   111              - section: defaults
   112                key: remote_port
   113            env:
   114              - name: ANSIBLE_REMOTE_PORT
   115            vars:
   116              - name: ansible_port
   117              - name: ansible_ssh_port
   118        remote_user:
   119            description:
   120                - User name with which to login to the remote server, normally set by the remote_user keyword.
   121                - If no user is supplied, Ansible will let the ssh client binary choose the user as it normally
   122            ini:
   123              - section: defaults
   124                key: remote_user
   125            env:
   126              - name: ANSIBLE_REMOTE_USER
   127            vars:
   128              - name: ansible_user
   129              - name: ansible_ssh_user
   130        pipelining:
   131            default: ANSIBLE_PIPELINING
   132            description:
   133              - Pipelining reduces the number of SSH operations required to execute a module on the remote server,
   134                by executing many Ansible modules without actual file transfer.
   135              - This can result in a very significant performance improvement when enabled.
   136              - However this conflicts with privilege escalation (become).
   137                For example, when using sudo operations you must first disable 'requiretty' in the sudoers file for the target hosts,
   138                which is why this feature is disabled by default.
   139            env:
   140              - name: ANSIBLE_PIPELINING
   141              #- name: ANSIBLE_SSH_PIPELINING
   142            ini:
   143              - section: defaults
   144                key: pipelining
   145              #- section: ssh_connection
   146              #  key: pipelining
   147            type: boolean
   148            vars:
   149              - name: ansible_pipelining
   150              - name: ansible_ssh_pipelining
   151        private_key_file:
   152            description:
   153                - Path to private key file to use for authentication
   154            ini:
   155              - section: defaults
   156                key: private_key_file
   157            env:
   158              - name: ANSIBLE_PRIVATE_KEY_FILE
   159            vars:
   160              - name: ansible_private_key_file
   161              - name: ansible_ssh_private_key_file
   162        control_path:
   163          description:
   164            - This is the location to save ssh's ControlPath sockets, it uses ssh's variable substitution.
   165            - Since 2.3, if null, ansible will generate a unique hash. Use `%(directory)s` to indicate where to use the control dir path setting.
   166          env:
   167            - name: ANSIBLE_SSH_CONTROL_PATH
   168          ini:
   169            - key: control_path
   170              section: ssh_connection
   171        control_path_dir:
   172          default: ~/.ansible/cp
   173          description:
   174            - This sets the directory to use for ssh control path if the control path setting is null.
   175            - Also, provides the `%(directory)s` variable for the control path setting.
   176          env:
   177            - name: ANSIBLE_SSH_CONTROL_PATH_DIR
   178          ini:
   179            - section: ssh_connection
   180              key: control_path_dir
   181        sftp_batch_mode:
   182          default: 'yes'
   183          description: 'TODO: write it'
   184          env: [{name: ANSIBLE_SFTP_BATCH_MODE}]
   185          ini:
   186          - {key: sftp_batch_mode, section: ssh_connection}
   187          type: bool
   188        scp_if_ssh:
   189          default: smart
   190          description:
   191            - "Prefered method to use when transfering files over ssh"
   192            - When set to smart, Ansible will try them until one succeeds or they all fail
   193            - If set to True, it will force 'scp', if False it will use 'sftp'
   194          env: [{name: ANSIBLE_SCP_IF_SSH}]
   195          ini:
   196          - {key: scp_if_ssh, section: ssh_connection}
   197        use_tty:
   198          version_added: '2.5'
   199          default: 'yes'
   200          description: add -tt to ssh commands to force tty allocation
   201          env: [{name: ANSIBLE_SSH_USETTY}]
   202          ini:
   203          - {key: usetty, section: ssh_connection}
   204          type: bool
   205          yaml: {key: connection.usetty}
   206  '''
   207  
   208  class Connection(SSHConnection):
   209      ''' ssh based connections for powershell via packer'''
   210  
   211      transport = 'packer'
   212      has_pipelining = True
   213      become_methods = []
   214      allow_executable = False
   215      module_implementation_preferences = ('.ps1', '')
   216  
   217      def __init__(self, *args, **kwargs):
   218          super(Connection, self).__init__(*args, **kwargs)