我有许多Ansible环境:
environments
dev
hosts
group_vars/
prod
hosts
group_vars/
我需要创建一个“设置”剧本,它将复制我使用的环境的group_vars
中的一些文件。
例如ansible-playbook -i environments/dev setup.yml --extra-vars="target=server1"
应该将文件从server1复制到环境/ dev
目前我有任务:
tasks:
- name: Copy SSL certificate
fetch:
src: /path/to/file.crt
dest: <inventoty_path>
flat: yes
但我不知道如何使用<inventory_path>
。
是否存在设置当前库存绝对路径的变量?或者获得它的方法(没有为此设置额外的变量)?
有几个“特殊变量”:
ansible_inventory_sources
inventory_dir
inventory_file
https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html
还有一个配置选项inventory
:https://docs.ansible.com/ansible/2.4/intro_configuration.html#inventory
您还可以设置环境变量:https://docs.ansible.com/ansible/2.4/config.html#envvar-ANSIBLE_INVENTORY
有一个魔术变量inventory_dir
,它返回当前库存文件的路径。 Doc:https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts