I'm trying to provision Ansible playbook using packer on Windows AMI.
That's my packer template:
{
"variables": {
"aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}",
"aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
"aws_region": "{{env `AWS_DEFAULT_REGION`}}",
"aws_source_ami": "*****",
"ssh_username": "{{env `AWS_AMI_USERNAME`}}",
"aws_instance_type": "m1.medium",
"name": "windows2012-...",
"packer_dir": "/opt/packer",
"home": "{{env `HOME`}}"
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "{{user `aws_region`}}",
"source_ami": "{{user `aws_source_ami`}}",
"ami_regions": ["{{user `aws_region`}}"],
"instance_type": "{{user `aws_instance_type`}}",
"communicator": "winrm",
"winrm_username": "Administrator",
"winrm_use_ssl": true,
"winrm_insecure": true,
"winrm_timeout": "12h",
"user_data_file": "scripts/userdata_setup.ps1",
"ami_name": "{{user `name`}}-ami",
"ami_description": "{{user `name`}}-ami",
"associate_public_ip_address": true,
"launch_block_device_mappings": [{
"device_name": "/dev/xvda",
"volume_type": "gp2",
"volume_size": 50,
"delete_on_termination": true
}],
"tags": {
"artifact": "{{user `name`}}"
}
}],
"provisioners": [
{
"type": "powershell",
"script": "scripts/ConfigureRemotingForAnsible.ps1"
},
{
"type": "ansible",
"playbook_file": "/path/to/playbook_file.yml",
"extra_arguments" : [
"--extra-vars", "ansible_user=Administrator ansible_connection=winrm ansible_winrm_server_cert_validation=ignore"
]
}
]
}
When I'm running packer build my_template.json
I'm getting the following error while the Ansible provisioner is running:
amazon-ebs: TASK [Gathering Facts] *********************************************************
amazon-ebs: fatal: [default]: UNREACHABLE! => {"changed": false, "msg":
"ssl: HTTPSConnectionPool(host='127.0.0.1', port=5986): Max retries
exceeded with url: /wsman (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x102ba6f90>:
Failed to establish a new connection: [Errno 61] Connection refused',))", "unreachable": true}
I guess I'm doing something wrong (why the host is 127.0.0.1?), but I haven't found any documentation about running ansible using packer on Windows in AMI.
Does anyone knows what am I doing wrong? How can I resolve my issue?
Best regards,
Adam
答案 0 :(得分:0)
您必须按照文档Packer Documentation - Ansible: winrm communicator中的说明操作,并使用自定义连接插件并使用以下ansible
配置工具:
"extra_arguments": [
"--connection", "packer",
"--extra-vars", "ansible_shell_type=powershell ansible_shell_executable=None"
]