gpt4 book ai didi

amazon-web-services - 在 AWS 中使用 Packer 在 Windows 上运行 Ansible

转载 作者:行者123 更新时间:2023-12-04 08:09:30 26 4
gpt4 key购买 nike

我正尝试在 Windows AMI 上使用加壳器配置 Ansible 剧本。
那是我的打包机模板:

{
"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"
]
}
]
}

当我运行 packer build my_template.json
Ansible provisioner 运行时出现以下错误:

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}

我想我做错了什么(为什么主机是 127.0.0.1?),但我还没有找到任何关于在 AMI 中的 Windows 上使用加壳器运行 ansible 的文档。

有谁知道我做错了什么?我该如何解决我的问题?


最好的问候,
亚当

最佳答案

您必须遵循文档中的说明 Packer Documentation - Ansible: winrm communicator并使用自定义连接插件并使用以下 ansible provisioner args:

  "extra_arguments": [
"--connection", "packer",
"--extra-vars", "ansible_shell_type=powershell ansible_shell_executable=None"
]

关于amazon-web-services - 在 AWS 中使用 Packer 在 Windows 上运行 Ansible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43583640/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com