作者blackspace98 (~我爱夏天~)
看板Linux
标题[问题] ansible 问题请教
时间Tue Mar 29 21:02:31 2022
我照着网路的范例,弄了一个范例
- 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://webptt.com/cn.aspx?n=bbs/Linux/M.1648558953.A.937.html
※ 编辑: blackspace98 (114.25.80.207 台湾), 03/29/2022 21:03:22
1F:→ yan12125: {{ result.stdout_lines+["OS","version"] }} 试试? 03/30 22:09
2F:→ blackspace98: 感谢提供方向,可以了,谢谢! 03/31 21:16