[問題] ansible 問題請教

看板Linux作者 (~我愛夏天~)時間2年前 (2022/03/29 21:02), 2年前編輯推噓0(002)
留言2則, 2人參與, 2年前最新討論串1/1
我照著網路的範例,弄了一個範例 - hosts: all vars: - packages: ssh tasks: - name: List {{ packages }} updated packages shell: yum list installed | grep {{ packages }} | awk '{print $1 " " $2}' register: result args: warn: no - debug: msg="{{ result.stdout_lines }}" - debug: msg: - "OS {{ hostvars[inventory_hostname].ansible_distribution }}" - "version {{ hostvars[inventory_hostname].ansible_distribution_version }}" 結果如下 TASK [debug] ****************************************************************** ok: [LAB] => { "msg": [ "libssh2.x86_64 1.8.0-4.el7", "openssh.x86_64 7.4p1-21.el7", "openssh-clients.x86_64 7.4p1-21.el7", "openssh-server.x86_64 7.4p1-21.el7", "sshpass.x86_64 1.06-2.el7" ] } TASK [debug] ******************************************************************* ok: [LAB] => { "msg": [ "OS CentOS", "version 7.9" ] } 如果想要變成把OS的資訊和套件版本一起顯示,可以怎麼改呢? ok: [LAB] => { "msg": [ "OS CentOS", "version 7.9", "libssh2.x86_64 1.8.0-4.el7", "openssh.x86_64 7.4p1-21.el7", "openssh-clients.x86_64 7.4p1-21.el7", "openssh-server.x86_64 7.4p1-21.el7", "sshpass.x86_64 1.06-2.el7" ] } 謝謝您了 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.25.80.207 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1648558953.A.937.html ※ 編輯: blackspace98 (114.25.80.207 臺灣), 03/29/2022 21:03:22

03/30 22:09, 2年前 , 1F
{{ result.stdout_lines+["OS","version"] }} 試試?
03/30 22:09, 1F

03/31 21:16, 2年前 , 2F
感謝提供方向,可以了,謝謝!
03/31 21:16, 2F
文章代碼(AID): #1YGmDfat (Linux)
文章代碼(AID): #1YGmDfat (Linux)