Я хочу сделать файл AMI из упаковщика и откликаться.
Я перепробовал много настроек, но у меня все еще есть проблема подключения к экземпляру.
Вот мой упаковщик конф:
{
"variables": {
"aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}",
"aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
"region": "us-east-1"
},
"builders": [
{
"type": "amazon-ebs",
"access_key": "{{ user `aws_access_key` }}",
"secret_key": "{{ user `aws_secret_key` }}",
"region": "{{ user `region` }}",
"instance_type": "t2.micro",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "*Windows_Server-2012-R2*English-64Bit-Base*",
"root-device-type": "ebs"
},
"most_recent": true,
"owners": "amazon"
},
"ami_name": "packer-demo-{{timestamp}}",
"user_data_file": "userdata/windows-aws.txt",
"communicator": "winrm",
"winrm_username": "Administrator"
}],
"provisioners": [{
"type": "powershell",
"inline": [
"dir c:\\"
]
},
{
"type": "ansible",
"playbook_file": "./win-playbook.yml",
"extra_arguments": [
"--connection", "packer", "-vvv",
"--extra-vars", "ansible_shell_type=powershell ansible_shell_executable=None"
]
}]
}
Скрипт пользовательских данных активирует winrm в экземпляре AWS:
<powershell>
winrm quickconfig -q
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow
netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
net stop winrm
sc config winrm start=auto
net start winrm
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope LocalMachine
</powershell>
Вот файл win-playbook.yml:
---
- hosts: all
tasks:
- win_ping:
У меня есть файл packer.py, установленный в каталоге ~ / .ansible / plugins / connection_plugins / и настроенный в ~ / .ansible.cfg:
root@ip-172-31-30-11:~/demo# grep connection_plugins /etc/ansible/ansible.cfg
connection_plugins = /root/.ansible/plugins/connection_plugins
root@ip-172-31-30-11:~/demo# ll /root/.ansible/plugins/connection_plugins
total 16
drwx------ 2 root root 4096 May 2 16:58 ./
drwx------ 4 root root 4096 May 2 17:11 ../
-rwx--x--x 1 root root 511 May 2 16:53 packer.py*
, а затем это ошибка вывода:
==> amazon-ebs: Provisioning with Ansible...
==> amazon-ebs: Executing Ansible: ansible-playbook --extra-vars packer_build_name=amazon-ebs packer_builder_type=amazon-ebs -i /tmp/packer-provisioner-ansible962278842 /root/demo/win-playbook.yml -e ansible_ssh_private_key_file=/tmp/ansible-key842946567 --connection packer -vvv --extra-vars ansible_shell_type=powershell ansible_shell_executable=None
amazon-ebs: ansible-playbook 2.5.2
amazon-ebs: config file = /etc/ansible/ansible.cfg
amazon-ebs: configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
amazon-ebs: ansible python module location = /usr/lib/python2.7/dist-packages/ansible
amazon-ebs: executable location = /usr/bin/ansible-playbook
amazon-ebs: python version = 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
amazon-ebs: Using /etc/ansible/ansible.cfg as config file
amazon-ebs: Parsed /tmp/packer-provisioner-ansible962278842 inventory source with ini plugin
amazon-ebs:
amazon-ebs: PLAYBOOK: win-playbook.yml *****************************************************
amazon-ebs: 1 plays in /root/demo/win-playbook.yml
amazon-ebs:
amazon-ebs: PLAY [all] *********************************************************************
amazon-ebs:
amazon-ebs: TASK [Gathering Facts] *********************************************************
amazon-ebs: task path: /root/demo/win-playbook.yml:2
amazon-ebs: Using module file /usr/lib/python2.7/dist-packages/ansible/modules/windows/setup.ps1
amazon-ebs: <127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: root
amazon-ebs: The full traceback is:
amazon-ebs: Traceback (most recent call last):
amazon-ebs: File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 138, in run
amazon-ebs: res = self._execute()
amazon-ebs: File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 558, in _execute
amazon-ebs: result = self._handler.run(task_vars=variables)
amazon-ebs: File "/usr/lib/python2.7/dist-packages/ansible/plugins/action/normal.py", line 46, in run
amazon-ebs: result = merge_hash(result, self._execute_module(task_vars=task_vars, wrap_async=wrap_async))
amazon-ebs: File "/usr/lib/python2.7/dist-packages/ansible/plugins/action/__init__.py", line 705, in _execute_module
amazon-ebs: self._make_tmp_path()
amazon-ebs: File "/usr/lib/python2.7/dist-packages/ansible/plugins/action/__init__.py", line 251, in _make_tmp_path
amazon-ebs: result = self._low_level_execute_command(cmd, sudoable=False)
amazon-ebs: File "/usr/lib/python2.7/dist-packages/ansible/plugins/action/__init__.py", line 902, in _low_level_execute_command
amazon-ebs: rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
amazon-ebs: File "/usr/lib/python2.7/dist-packages/ansible/plugins/connection/ssh.py", line 976, in exec_command
amazon-ebs: use_tty = self.get_option('use_tty')
amazon-ebs: File "/usr/lib/python2.7/dist-packages/ansible/plugins/__init__.py", line 58, in get_option
amazon-ebs: option_value = C.config.get_config_value(option, plugin_type=get_plugin_class(self), plugin_name=self._load_name, variables=hostvars)
amazon-ebs: File "/usr/lib/python2.7/dist-packages/ansible/config/manager.py", line 284, in get_config_value
amazon-ebs: value, _drop = self.get_config_value_and_origin(config, cfile=cfile, plugin_type=plugin_type, plugin_name=plugin_name, keys=keys, variables=variables)
amazon-ebs: File "/usr/lib/python2.7/dist-packages/ansible/config/manager.py", line 304, in get_config_value_and_origin
amazon-ebs: defs = self._plugins[plugin_type][plugin_name]
amazon-ebs: KeyError: 'connection'
amazon-ebs: fatal: [default]: FAILED! => {
amazon-ebs: "msg": "Unexpected failure during module execution.",
amazon-ebs: "stdout": ""
amazon-ebs: }
amazon-ebs: to retry, use: --limit @/root/demo/win-playbook.retry
amazon-ebs:
amazon-ebs: PLAY RECAP *********************************************************************
amazon-ebs: default : ok=0 changed=0 unreachable=0 failed=1
версия упаковщика: 1.2.3
версия для ответа: 2.5.2