ansible - Packer 的 ansible-local 不会将 packer 变量作为额外的变量获取
问题描述
我有一个在 azure 上创建图像的打包程序代码。我正在使用 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 来继承上面打包器命令的值。
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
可以看出,变量没有得到填充。我将示例代码片段放置在打包程序文件中以供参考。
Packer 变量配置:
{
"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`}}"
}
Packer 供应商配置:
"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"
}]
}
请帮我解决问题。
解决方案
问题已解决。变量的位置需要在变量部分互换。我也尝试保持左侧和右侧的变量名称相同。有效
推荐阅读
- javascript - 您将如何向接受参数的用户提供 API 端点?(GrapQL/ApolloServer)
- javascript - 从 crypto.createHash() 获取不同的哈希值
- powershell - 如何设置 Open-XML-PowerTools
- sql-server - 在将 XML 数据存储到 SQL 的过程中,在 SQL 中使用 OPENXML 查询 XML 文件
- python - 我可以让 binned_statistic_2d 仅返回范围内 bin 的 bin 编号吗?
- java - 间谍 Guice 模块在单元测试期间抛出 CreationException
- c++ - 没有虚拟析构函数的 novtable 基类上的删除行为
- c# - ASP.NET API 向 Angular 返回奇怪的值
- kubernetes - 除了 Kubernetes 中的 pod,我还能从其他资源中获取事件吗?
- python - 机器学习编码分类数据回归的潜在问题