我正在寻找在另一个任务中运行任务的方法
- name: Get object facts
checkpoint_policy_pkg_facts:
register: results
- name: "set fact for policy pkg selection"
set_fact:
pkges: "{{ results | json_query(query) }}"
vars:
query: "ansible_facts.checkpoint_access_layers.packages[].name"
- name: Get object facts
checkpoint_policy_pkg_facts:
name: "{{ item }}"
register: results
with_items: "{{ pkges }}"
- name: "set fact for policy pkg selection"
set_fact:
pkgname: "{{ results | json_query(query) }}"
vars:
query: "results[?ansible_facts.checkpoint_access_layers.\"installation-targets-revision\"[?\"cluster-members-revision\"[?\"target-name\"=='{{ item }}']]].item | [0]"
with_items: "{{ targets }}"
输出如下
"PolicyPKG1",
"PolicyPKG2",
"Standard"
我想使用以下任务将pkgname插入另一个任务,因为我的目标项目很大,所以我想使用以下任务将相应的pkgname插入servicenow
- name: Create a change request
snow_record:
state: present
table: u_device
username: admin
password:
instance: dev778899
data:
u_name: "{{ pkgname }}"
答案 0 :(得分:0)
您可以将pkgname
注册为变量,以后再使用pkgname.stdout_lines
作为变量,
- name: "set fact for policy pkg selection"
register: pkgname
vars:
query: "results[?ansible_facts.checkpoint_access_layers.\"installation-targets-revision\"[?\"cluster-members-revision\"[?\"target-name\"=='{{ item }}']]].item | [0]"
with_items: "{{ targets }}"
接下来:
- name: Create a change request
snow_record:
state: present
table: u_device
username: admin
password:
instance: dev778899
data:
u_name: "{{ item }}"
with_items: "{{ pkgname.stdout_lines }}"