我正在尝试计算role_path变量的值,以便在其他角色中使用它作为参考点。然而,问题是,当我的变量在另一个角色中使用时,它具有另一个角色的值,而不是声明它的时候的值。
我通过使用当前变量的值的echo命令并注册输出来解决这个问题,如下所示。
- name: get ansible base path from current role_path
command: echo {{ role_path }}/../../
register: ansible_base_path_out
- name: save ansible base path variable for future
Ansible unbale to run python script from playbook如果我尝试手动运行python脚本,它工作得很好。但是,当我执行Playbook中的脚本时,它无法识别变量。我得到了以下错误: TASK [Updates the current location for the test] *****************************************************************************************************************************************
我正在尝试通过运行
ansible -m debug -a 'var=ansible_distribution' all
但我得到了
my_ansible_host0 | SUCCESS => {
"ansible_distribution": "VARIABLE IS NOT DEFINED!"
}
不过,我似乎可以在我的jinja模板中使用{{ansible_distribution}}。为什么会这样呢?(例如,这是否与我尚未弄清楚的事实和变量之间的区别有关?)如何更改命令以使其打印出ansible_distribution的值
我在亚马逊网络服务中有很多EC2服务器,我想根据从ansible_facts收集的事实对它们进行分类(通过模块设置)。例如,拥有一个组"CentOS“,其中ansible_facts['distribution'] == 'CentOS'等等。但是有了文件inventory/constructed.yml
plugin: constructed
strict: False
keyed_groups:
# this creates a group per distro (distro_CentOS, distro_Debian) and assigns
我是Ansible的新手,我以这种方式使用ansible命令失败了:
ansible host -a "/sbin/swapoff -a && /sbin/swapon -a"
只有这个起作用了
ansible host -a "/sbin/swapoff -a
ansible host -a "/sbin/swapon -a
我正在考虑制作一本剧本,也许从以下几个方面开始:
- name: Turn off swap
shell : "swapoff -a"
- name: Turn on swap
shell : &
把这个放进group_vars/all
default_environment:
HOME2: "{{ ansible_env.HOME }}"
在任务中使用以定义环境时:
environment:
"{{ default_environment }}"
我明白了:
The field 'environment' has an invalid value, which includes an undefined variable. The error was: {u'HOME2': u'{{ ansible_env