Ansible:更改剧本位置 [英] Ansible: Change playbooks location
问题描述
我在/etc/ansible/playbooks 中有所有剧本,我想在电脑上的任何地方执行它们
I have all playbooks in /etc/ansible/playbooks and I want to execute them anywhere on the pc
我尝试在 ansible.cfg 中配置 playbook_dir 变量
I tried to configure playbook_dir variable in ansible.cfg
[defaults]
playbook_dir = /etc/ansible/playbooks/
并尝试将 ANSIBLE_PLAYBOOK_DIR 变量放入 ~/.bashrc
and tried to put ANSIBLE_PLAYBOOK_DIR variable in ~/.bashrc
export ANSIBLE_PLAYBOOK_DIR=/etc/ansible/playbooks/
但我只在两种情况下都遇到相同的错误:
but I only got the same error in both cases:
nor@nor:~$ ansible-playbook test3.yaml
ERROR! the playbook: test3.yaml could not be found
这是我的 ansible 版本:
This is my ansible version:
ansible 2.9.7
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/nor/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.7.3 (default, Oct 7 2019, 12:56:13) [GCC 8.3.0]
有人知道问题所在以及如何解决吗?
Does anyone know the problem and how to solve it?
推荐答案
正如其他人所说,ANSIBLE_PLAYBOOK_DIR 用于设置角色/、文件/等的相对目录.恕我直言,它不是很有用.
As others have said, ANSIBLE_PLAYBOOK_DIR is for setting the relative directory for roles/, files/, etc. IMHO, it's not terribly useful.
如果我理解操作,这就是我使用所有版本的 ansible 实现类似结果的方式......
If I understand the op, this is how I accomplish a similar result with all versions of ansible ...
PPWD=$PWD cd /my/playbook/dir && ansible-playbook my_playbook.yml; cd $PPWD
解释,
PPWD=$PWD 就是记住当前/现在/上一个工作目录,然后cd/my/playbook/dir 如果成功运行 ansible-playbook my_playbook.yml (一切都是相对的);不管怎样,总是改回之前的工作目录
PPWD=$PWD is to remember the current/present/previous working directory, then cd /my/playbook/dir and if that succeeds run ansible-playbook my_playbook.yml (everything is relative from there); regardless, always change back to the previous working directory
这篇关于Ansible:更改剧本位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!