仅返回 Ansible playbook 中的“msg:”

The*_*Mob 4 yaml ansible

我有一个简单的剧本来查询包版本

---
- name: version find
  hosts: all
  become: yes


    tasks:
          - name: query
            shell: *shell command*
            register: info
            no_log: true

           - debug:
                  msg: " {{inventory_hostname}} blah {{info.stdout}}blah"
Run Code Online (Sandbox Code Playgroud)

我得到的输出包含大量垃圾,这使得在不进行编辑的情况下解析/使用输出变得困难:

   ok: [hostname] => {
    "msg": " *hostname* blah *info* blah"
   }
Run Code Online (Sandbox Code Playgroud)

我正在尝试找到一种解决方案,只返回不带“ok:”的消息,以及随之而来的 JSON 式垃圾。

我尝试no_log:True在 YAML 文件和 ansible.cfg 文件中进行设置,但没有成功。

Vla*_*tka 6

使用回调community.general.diy自己动手)。看

shell> ansible-doc -t callback community.general.diy
Run Code Online (Sandbox Code Playgroud)

例如,

shell> ansible-doc -t callback community.general.diy
Run Code Online (Sandbox Code Playgroud)

给出

shell> cat pb.yml
- hosts: localhost

  tasks:

    - command: uname -o
      register: info

    - debug:
        msg: ""
      vars:
        ansible_callback_diy_runner_on_ok_msg: |
          msg: {{ inventory_hostname }} {{ info.stdout }}
Run Code Online (Sandbox Code Playgroud)