Ansible:更改剧本的位置 [英] Ansible: Change playbooks location

查看:434
本文介绍了Ansible:更改剧本的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在/etc/ansible/playbooks中都有所有剧本,我想在PC上的任何地方执行它们

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 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆