我有一个在天蓝色上创建图像的打包器代码。我使用ansible-local配置程序来安装所需的工具。我执行以下命令
packer build -force -var azure_subscription_id=**** -var azure_tennant_id=**** -var azure_application_id=**** -var azure_application_password=**** -var nexus_user=**** -var nexus_password=**** build_packer_azure_image.json
但是,ansible本地配置程序将执行以下comaand作为打包程序配置程序的一部分。我需要两个变量nexus_username和nexus_password来继承上面的packer命令中的值。
cd / tmp / packer-provisioner-ansible-local / 5b04201f-b988-90e6-b769-24822ffc5333&& ANSIBLE_FORCE_COLOR = 1 PYTHONUNBUFFERED = 1 ansible-playbook /tmp/packer-provisioner-ansible-local/5b04201f-b988-90e6-b769-24822ffc5333/provision.yml --extra-vars" packer_build_name = azure-arm packer_builder_type = azure -arm packer_http_addr =" --extra-vars' nexus_username = nexus_password =' -c local -i / tmp / packer-provisioner-ansible-local / 5b04201f-b988-90e6-b769-24822ffc5333 / packer-provisioner-ansible-local158977121
可以看出,变量没有填充。我将示例代码片段放在打包器文件中以供参考。
{
"variables": {
"azure_subscription_id": "{{env `azure_subscription_id`}}",
"azure_tennant_id": "{{env `azure_tennant_id`}}",
"azure_application_id": "{{env `azure_application_id`}}",
"azure_application_password": "{{env `azure_application_password`}}",
"ansible_nexus_user": "{{env `nexus_user`}}",
"ansible_nexus_password": "{{env `nexus_password`}}"
}
"provisioners": [
{
"type": "shell",
"scripts": [
"../scripts/install_ansible.sh"
]
},
{
"type": "ansible-local",
"playbook_dir": "../workstation-playbook",
"playbook_file": "../workstation-playbook/provision.yml",
"extra_arguments": [ "--extra-vars 'nexus_username={{user `ansible_nexus_user`}} nexus_password={{user `ansible_nexus_password`}}'" ]
},
{
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",
"inline": [
"/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
],
"inline_shebang": "/bin/sh -x",
"type": "shell"
}]
}
请帮我解决问题。
答案 0 :(得分:0)
问题已解决。变量的位置需要在变量部分中互换。我也试图将变量的名称保持在左侧和右侧相同。它工作