#1. Confirm your hosts in hosts file
# [root@Ansible-S1 ~]# cat /etc/ansible/hosts
[web]
192.168.184.130
192.168.184.131
#2. Run ad-hoc command 1
#[root@Ansible-S1 ~]# ansible web -a /bin/date
192.168.184.130 | CHANGED | rc=0 >>
Mon Nov 11 23:28:46 EST 2019
192.168.184.131 | CHANGED | rc=0 >>
Mon Nov 11 23:28:46 EST 2019
#3. Run ad-hoc command 2
# [root@Ansible-S1 ~]# ansible web -a uptime
192.168.184.130 | CHANGED | rc=0 >>
23:28:54 up 3:07, 3 users, load average: 0.00, 0.00, 0.00
192.168.184.131 | CHANGED | rc=0 >>
23:28:54 up 3:07, 2 users, load average: 0.00, 0.00, 0.00
#4. Run ad-hoc command 3
# [root@Ansible-S1 ~]# ansible web -m ping
192.168.184.130 | SUCCESS => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/libexec/platform-python”
},
“changed”: false,
“ping”: “pong”
}
192.168.184.131 | SUCCESS => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/libexec/platform-python”
},
“changed”: false,
“ping”: “pong”
}
#5. Run ad-hoc command 4
#[root@Ansible-S1 ~]# ansible web -m yum -a “name=openssl state=latest”
192.168.184.130 | SUCCESS => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/libexec/platform-python”
},
“changed”: false,
“msg”: “Nothing to do”,
“rc”: 0,
“results”: [
“Installed: openssl”
]
}
192.168.184.131 | SUCCESS => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/libexec/platform-python”
},
“changed”: false,
“msg”: “Nothing to do”,
“rc”: 0,
“results”: [
“Installed: openssl”
]
}
#6. Use -C (check) mode to make sure the system is up to date
[root@Ansible-S1 ~]# ansible web -C -m yum -a “name=kernel state=latest”
192.168.184.130 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/libexec/platform-python”
},
“changed”: true,
“msg”: “Check mode: No changes made, but would have if not in check mode”,
“rc”: 0,
“results”: [
“Installed: kernel”
]
}
192.168.184.131 | CHANGED => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/libexec/platform-python”
},
“changed”: true,
“msg”: “Check mode: No changes made, but would have if not in check mode”,
“rc”: 0,
“results”: [
“Installed: kernel”
]
}
Leave a comment