Vagrant ansible: pick var fron 环境变量
Vagrant ansible: pick var fron environment variable
这是我的 ansible_local
相关 Vagrantfile
代码:
config.vm.provision "ansible_local" do |ansible|
ansible.become = true
ansible.inventory_path = '/vagrant/provisioning/inventory/hosts.ini'
ansible.playbook = "/vagrant/provisioning/playbook.yml"
ansible.limit = 'all'
ansible.galaxy_role_file = "/vagrant/provisioning/requirements.yml"
ansible.galaxy_roles_path = "/etc/ansible/roles"
ansible.galaxy_command = "sudo ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force"
end
如您所见,ansible.limit
是 all
。
├── ansible.cfg
├── provisioning
│ ├── group_vars
│ │ └── all.yml
│ ├── inventory
│ │ ├── hosts.ini
│ │ └── hosts.yml
│ ├── playbook.yml
│ └── requirements.yml
└── Vagrantfile
all.yml
内容为:
solr_cores:
mssql_restore_backups: false
我需要替换 mssql_restore_backup
从环境变量中获取的默认值。
是否可以将环境变量值传递给 ansible provisioner?
有什么想法吗?
在 Ansible 中,具有市长优先级的变量是 extra-vars
,您可以将它们添加到您的 Vagrantfile 中,如下所示
ansible.extra_vars = {
mssql_restore_backup: $MSSQLRESTOREBACKUP
}
文档:
https://www.vagrantup.com/docs/provisioning/ansible_common#extra_vars
这是我的 ansible_local
相关 Vagrantfile
代码:
config.vm.provision "ansible_local" do |ansible|
ansible.become = true
ansible.inventory_path = '/vagrant/provisioning/inventory/hosts.ini'
ansible.playbook = "/vagrant/provisioning/playbook.yml"
ansible.limit = 'all'
ansible.galaxy_role_file = "/vagrant/provisioning/requirements.yml"
ansible.galaxy_roles_path = "/etc/ansible/roles"
ansible.galaxy_command = "sudo ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force"
end
如您所见,ansible.limit
是 all
。
├── ansible.cfg
├── provisioning
│ ├── group_vars
│ │ └── all.yml
│ ├── inventory
│ │ ├── hosts.ini
│ │ └── hosts.yml
│ ├── playbook.yml
│ └── requirements.yml
└── Vagrantfile
all.yml
内容为:
solr_cores:
mssql_restore_backups: false
我需要替换 mssql_restore_backup
从环境变量中获取的默认值。
是否可以将环境变量值传递给 ansible provisioner?
有什么想法吗?
在 Ansible 中,具有市长优先级的变量是 extra-vars
,您可以将它们添加到您的 Vagrantfile 中,如下所示
ansible.extra_vars = {
mssql_restore_backup: $MSSQLRESTOREBACKUP
}
文档:
https://www.vagrantup.com/docs/provisioning/ansible_common#extra_vars