我想将 ansible fact 变量的值存储在其他变量中,并且还想检查 fact 变量是否为空
下面是我的代码,我可以打印 ansible_local fact 变量的值,但我希望将该值存储在另一个变量 xyz 中。还想检查 ansible_local.sj.inventory.as_tag 变量值是否为空
- name: -> Apply common configuration to {{ target }} nodes
hosts: "{{ target }}"
gather_facts: True
user: root
pre_tasks:
- setup:
filter: ansible_local
tasks:
- action: debug msg="{{ ansible_local.sj.inventory.as_tag }}"
样品输出:
TASK: [debug msg="{{ansible_local.sj.inventory.as_tag}}"]
***********
Monday 09 May 2016 09:48:49 -0700 (0:00:01.375) 0:00:02.785
************
ok: [abcserver] => {
"msg": "abcd-123"
答案1
您可以使用set_fact 模块。
这是一个例子....
- name: -> Apply common configuration to {{ target }} nodes
hosts: "{{ target }}"
gather_facts: True
user: root
pre_tasks:
- setup:
filter: ansible_local
- set_fact:
tag: "{{ ansible_local.sj.inventory.as_tag }}"
- debug:
var: tag