Ansible 更新 yum 人性化输出
Ansible Update yum human friendly output
我想在 运行 yum 更新
时从 Ansible 获得更好的输出格式
我的剧本:
- hosts: all
user: ansbl
gather_facts: true
become: true
tasks:
- name: Check YUM Updates
yum:
name: '*'
state: latest
update_cache: yes
skip_broken: yes
register: yum_output
when: ansible_facts['os_family'] == "RedHat"
check_mode: yes
- debug:
msg: "{{ yum_output.changes.updated }}"
when: ansible_facts['distribution'] == "RedHat"
我的输出:
TASK [debug] *******************************************************************
ok: [myhost] => {
"msg": [
[
"nss",
"3.44.0-7.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
],
[
"kernel-tools",
"3.10.0-1062.9.1.el7.x86_64 from rhui-rhel-7-server-rhui-rpms"
],
[
"nss-softokn-freebl",
"3.44.0-8.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
]
]
}
期望的输出:
TASK [debug] *******************************************************************
ok: [myhost] => {
"msg": [
"nss", "3.44.0-7.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
"kernel-tools", "3.10.0-1062.9.1.el7.x86_64 from rhui-rhel-7-server-rhui-rpms"
"nss-softokn-freebl", "3.44.0-8.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
]
}
我看到了一种从 dpkg 收集更新包的方法作为一项单独的任务,但如果可能的话,我想将其包含在一个调试任务中。我已经尝试通过管道传输到 list
和 join
,但这返回了相同的输出结果。
试试这个
- debug:
msg: "{{ msg[:-1].split('\n') }}"
vars:
msg: |-
{% for pkg in yum_output.changes.updated %}
{{ pkg.0 }}, {{ pkg.1 }}
{% endfor %}
when: ansible_facts['distribution'] == "RedHat"
我想在 运行 yum 更新
时从 Ansible 获得更好的输出格式我的剧本:
- hosts: all
user: ansbl
gather_facts: true
become: true
tasks:
- name: Check YUM Updates
yum:
name: '*'
state: latest
update_cache: yes
skip_broken: yes
register: yum_output
when: ansible_facts['os_family'] == "RedHat"
check_mode: yes
- debug:
msg: "{{ yum_output.changes.updated }}"
when: ansible_facts['distribution'] == "RedHat"
我的输出:
TASK [debug] *******************************************************************
ok: [myhost] => {
"msg": [
[
"nss",
"3.44.0-7.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
],
[
"kernel-tools",
"3.10.0-1062.9.1.el7.x86_64 from rhui-rhel-7-server-rhui-rpms"
],
[
"nss-softokn-freebl",
"3.44.0-8.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
]
]
}
期望的输出:
TASK [debug] *******************************************************************
ok: [myhost] => {
"msg": [
"nss", "3.44.0-7.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
"kernel-tools", "3.10.0-1062.9.1.el7.x86_64 from rhui-rhel-7-server-rhui-rpms"
"nss-softokn-freebl", "3.44.0-8.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
]
}
我看到了一种从 dpkg 收集更新包的方法作为一项单独的任务,但如果可能的话,我想将其包含在一个调试任务中。我已经尝试通过管道传输到 list
和 join
,但这返回了相同的输出结果。
试试这个
- debug:
msg: "{{ msg[:-1].split('\n') }}"
vars:
msg: |-
{% for pkg in yum_output.changes.updated %}
{{ pkg.0 }}, {{ pkg.1 }}
{% endfor %}
when: ansible_facts['distribution'] == "RedHat"