ansible 問題請教 - Linux
By Elma
at 2022-03-29T21:02
at 2022-03-29T21:02
Table of Contents
我照著網路的範例,弄了一個範例
- 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"
]
}
謝謝您了
--
- 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"
]
}
謝謝您了
--
Tags:
Linux
All Comments
By Mary
at 2022-04-02T09:08
at 2022-04-02T09:08
By Emma
at 2022-04-05T21:14
at 2022-04-05T21:14
Related Posts
安裝tigervnc後本機端桌面掛掉
By William
at 2022-03-27T17:54
at 2022-03-27T17:54
ubuntu 黑畫面當機
By Carol
at 2022-03-27T13:58
at 2022-03-27T13:58
fedora 35 + wayland + chromium + ibus,無法輸入中文
By Odelette
at 2022-03-27T00:41
at 2022-03-27T00:41
請問想學伺服器的新手 安裝哪個linux
By Yuri
at 2022-03-26T13:34
at 2022-03-26T13:34
CentOS fortran平行計算問題
By Susan
at 2022-03-23T22:27
at 2022-03-23T22:27