Ansible: Store command's stdout in new variable?

前端 未结 6 686
暗喜
暗喜 2020-12-22 22:35

Inside my playbook I\'d like to create a variable holding the output of an external command. Afterwards I want to make use of that variable in a couple of templates.

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 23:01

    If you want to go further and extract the exact information you want from the Playbook results, use JSON query language like jmespath, an example:

      - name: Sample Playbook
        // Fill up your task
        no_log: True
        register: example_output
    
      - name: Json Query
        set_fact:
          query_result:
            example_output:"{{ example_output | json_query('results[*].name') }}"
    

提交回复
热议问题