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