我编写了一个任务,如果需要重新启动,则仅打印该任务。我有这个 yum 模块输出,我需要提取单词“Complete | or_some_other_word”,并且此任务仅在上述单词存在时才会运行。
TASK [deploying_security_updates : Installed Packages] **************************************************************************************************************************************************************************************
ok: [192.168.8.26] => {
"yum_update": {
"changed": true,
"changes": {
"installed": [],
"updated": [
[
"xz",
"5.2.2-2.el7_9.x86_64 from rhel-remote"
],
[
"xz-libs",
"5.2.2-2.el7_9.x86_64 from rhel-remote"
]
]
},
"failed": false,
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-\n : manager\nThis system is not registered with an entitlement server. You can use subscription-manager to register.\n --> device-mapper-persistent-data-0.7.3-3.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> 7:device-mapper-event-1.02.170-6.el7_9.5.x86_64 from rhel-remote removed (updateinfo)\n --> libgnomekbd-3.26.0-3.el7.x86_64 from rhel-remote removed (updateinfo)\n --> cryptsetup-python-2.0.3-3.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> PackageKit-gstreamer-plugin-1.1.10-2.el7.x86_64 from rhel-remote removed (updateinfo)\n --> libstoragemgmt-1.6.2-4.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> PackageKit-gtk3-module-1.1.10-2.el7.x86_64 from rhel-remote removed (updateinfo)\n --> 7:device-mapper-event-1.02.149-8.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> setroubleshoot-plugins-3.0.67-3.el7.noarch from @anaconda/7.6 removed (updateinfo)\n --> libdrm-2.4.91-3.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> mesa-dri-drivers-18.3.4-12.el7_9.x86_64 from rhel-remote removed (updateinfo)\n --> subscription-manager-plugin-container-1.24.51-1.el7_9.x86_64 from rhel-remote removed (updateinfo)\n --> firewalld-0.6.3-13.el7_9.noarch from rhel-remote removed (updateinfo)\n --> gdb-7.6.1-114.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> grubby-8.28-26.el7.x86_64 from rhel-remote removed (updateinfo)\n --> hostname-3.13-3.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> 32:bind-libs-lite-9.11.4-26.P2.el7_9.9.x86_64 from rhel-remote removed (updateinfo)\n --> abrt-dbus-2.1.11-52.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> unzip-6.0-21.el7.x86_64 from @rhel-remote removed (updateinfo)\n --> realmd-0.16.1-12.el7_9.1.x86_64 from rhel-remote removed (updateinfo)\n --> 2:shadow-utils-4.1.5.1-25.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> libreport-2.1.11-53.el7.x86_64 from rhel-remote removed (updateinfo)\n --> 1:grub2-tools-minimal-2.02-0.87.el7_9.6.x86_64 from @rhel-remote removed (updateinfo)\n --> 1:grub2-pc-modules-2.02-0.87.el7_9.6.noarch from @rhel-remote removed (updateinfo)\n --> 1:make-3.82-23.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> anaconda-gui-21.48.22.147-1.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> 2:gedit-3.28.1-1.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> iptables-1.4.21-35.el7.x86_64 from rhel-remote removed (updateinfo)\n --> gnome-shell-extension-window-list-3.28.1-14.el7.noarch from @rhel-remote removed (updateinfo)\n --> plymouth-0.8.9-0.31.20140113.el7.x86_64 from @anaconda/7.6 re\n --> gnome-settings-daemon-3.28.1-11.el7_9.x86_64 from rhel-remote removed (updateinfo)\n --> 10:qemu-kvm-1.5.3-175.el7_9.6.x86_64 from rhel-remote removed (updateinfo)\n --> libcap-2.22-9.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> libvirt-daemon-driver-nodedev-4.5.0-36.el7_9.3.x86_64 from @rhel-remote removed (updateinfo)\n --> libblockdev-swap-2.18-3.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> tzdata-2018e-3.el7.noarch from @anaconda/7.6 removed (updateinfo)\n --> langtable-0.0.31-4.el7.noarch from rhel-remote removed (updateinfo)\n --> librdmacm-22.4-6.el7_9.x86_64 from rhel-remote removed (updateinfo)\n --> libreport-plugin-reportuploader-2.1.11-53.el7.x86_64 from rhel-remote removed (updateinfo)\n --> mesa-libglapi-18.3.4-12.el7_9.x86_64 from rhel-remote removed (updateinfo)\n --> sos-3.6-9.el7.noarch from @anaconda/7.6 removed (updateinfo)\n --> anaconda-tui-21.48.22.159-1.el7.x86_64 from rhel-remote removed (updateinfo)\n --> 3:irqbalance-1.0.7-12.el7.x86_64 from rhel-remote removed (updateinfo)\n --> libreport-plugin-ureport-2.1.11-53.el7.x86_64 from rhel-remote removed (updateinfo)\n --> systemd-219-78.el7_9.5.x86_64 from rhel-remote removed (updateinfo)\n --> python2-blockdev-2.18-5.el7.x86_64 from rhel-remote removed (updateinfo)\n --> pulseaudio-module-bluetooth-10.0-5.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> ipset-libs-6.38-2.el7.x86_64 from @anaconda/7.6 removed (updateinfo)\n --> lshw-B.02.18-17.el7.x86_64 from rhel-remote removed (updateinfo)\n --> libblockdev-crypto-2.18-5.el7.x86_64 from rhel-remote removed (updateinfo)\n --> libffi-3.0.13-19.el7.x86_64 from rhel-remote removed (updateinfo)\n2 package(s) needed (+0 related) for security, out of 401 available\nResolving Dependencies\n--> Running transaction check\n---> Package xz.x86_64 0:5.2.2-1.el7 will be updated\n---> Package xz.x86_64 0:5.2.2-2.el7_9 will be an update\n---> Package xz-libs.x86_64 0:5.2.2-1.el7 will be updated\n---> Package xz-libs.x86_64 0:5.2.2-2.el7_9 will be an update\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nUpdating:\n xz x86_64 5.2.2-2.el7_9 rhel-remote 229 k\n xz-libs x86_64 5.2.2-2.el7_9 rhel-remote 103 k\n\nTransaction Summary\n================================================================================\nUpgrade 2 Packages\n\nTotal download size: 332 k\nDownloading packages:\nNo Presto metadata available for rhel-remote\n--------------------------------------------------------------------------------\nTotal 1.3 MB/s | 332 kB 00:00 \nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Updating : xz-libs-5.2.2-2.el7_9.x86_64 1/4 \n Updating : xz-5.2.2-2.el7_9.x86_64 2/4 \n Cleanup : xz-5.2.2-1.el7.x86_64 3/4 \n Cleanup : xz-libs-5.2.2-1.el7.x86_64 4/4 \n Verifying : xz-libs-5.2.2-2.el7_9.x86_64 1/4 \n Verifying : xz-5.2.2-2.el7_9.x86_64 2/4 \n Verifying : xz-libs-5.2.2-1.el7.x86_64 3/4 \n Verifying : xz-5.2.2-1.el7.x86_64 4/4 \n\nUpdated:\n xz.x86_64 0:5.2.2-2.el7_9 xz-libs.x86_64 0:5.2.2-2.el7_9 \n\nComplete!\n"
]
}
}
答案1
你可以看看
文档
并可以使用
when: "'Complete' in yum_update.results"
或者
when: yum_update.results is search('Complete')
进一步问答