如何有效设置ansible set_facts

时间:2019-05-30 08:35:00

标签: ansible ansible-facts

我正在使用以下任务来设置事实,并在下一个任务中使用相同的事实。 一切都按预期工作,但我希望优化以下

有人帮我优化了

  tasks:
  - name: USE CUSTOM TYPE TO QUERY AVAILABLE SCRIPTS
    fmgr_query:
      adom: "{{ adom }}"
      object: "custom"
      custom_endpoint: "/pm/config/adom/{{ adom }}/_package/status/{{ FGT }}/{{ vdom }}"
    register: results
    tags: ADDLAG
    when: vdom != ""  or vdom is not defined

  - name: "set fact for policy pkg selection"
    set_fact:
      name: "{{ results  | json_query(query) }}"
    vars:
       query: "ansible_module_results.pkg"
    when: vdom != "" or vdom is not defined


  - name: USE CUSTOM TYPE TO QUERY AVAILABLE SCRIPTS
    fmgr_query:
      adom: "{{ adom }}"
      object: "custom"
      custom_endpoint: "/pm/config/adom/{{ adom }}/_package/status/{{ FGT }}"
    register: results
    tags: ADDLAG
    when: vdom == "" or vdom is not defined


  - name: Debug print value of operation_status.stdout
    debug:
      msg: '{{ results }}'
    tags: ADDLAG

  - name: "set fact for policy pkg selection"
    set_fact:
      name: "{{ results  | json_query(query) }}"
    vars:
        query: "results[].pkg|[0]"
    when: vdom == "" or vdom is not defined
  - name: Debug print valu of operation_status.stdout
    debug:
      msg: '{{ name }}'

0 个答案:

没有答案