标签:令行 stdout uptime 例子 pytho ansible err variable lines
接下来介绍一些后面章节中会用到的模块 , 也是很常用的模块。ping 模块
这个是测试远程节点的 SSH 连接是否就绪的常用模块。但它并不像 Linux 命令那样简单地
ping 一下远程节点 , 而是先检查能否通过 SSH 登录远程节点 , 再检查其 Python 版本能否满足要求 , 如果都满足则会返回 ping, 表示成功.ping 无须任何参数。因为 ping 是测试节点连接的可用性,所以通常在命令行中使用得较为频繁。下面是 ping 在命令行中的用法。
ansible all -m ping
---
- hosts: nginx
remote_user: root
tasks:
- debug:
msg: "systemc {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }}"
- name: display all variables/facts known for a host
debug:
var: hostvars[inventory_hostname]["ansible_default_ipv4"]["gateway"]
- shell: /usr/bin/uptime
register: result
- debug:
var: result
[root@server3 test]# ansible-playbook debug.yml
PLAY [nginx] *****
TASK [Gathering Facts] ***
ok: [192.168.1.4]
TASK [debug] *****
ok: [192.168.1.4] => {
"msg": "systemc 192.168.1.4 has gateway 192.168.1.254"
}
TASK [display all variables/facts known for a host] **
ok: [192.168.1.4] => {
"hostvars[inventory_hostname][\"ansible_default_ipv4\"][\"gateway\"]": "192.168.1.254"
}
TASK [shell] *****
changed: [192.168.1.4]
TASK [debug] *****
ok: [192.168.1.4] => {
"result": {
"changed": true,
"cmd": "/usr/bin/uptime",
"delta": "0:00:00.006414",
"end": "2020-11-27 09:43:52.697253",
"failed": false,
"rc": 0,
"start": "2020-11-27 09:43:52.690839",
"stderr": "",
"stderr_lines": [],
"stdout": " 09:43:52 up 13 days, 23:27, 2 users, load average: 0.00, 0.01, 0.05",
"stdout_lines": [
" 09:43:52 up 13 days, 23:27, 2 users, load average: 0.00, 0.01, 0.05"
]
}
}
标签:令行 stdout uptime 例子 pytho ansible err variable lines
原文地址:https://blog.51cto.com/13810716/2555442