Ansible Ad-hoc command

One of the great things about using Ansible as your configuration management tool of choice is its flexibility. Ad-hoc commands are commands which can be run individually to perform quick functions.These commands need not be performed later.
Ping check ansible servergroup
ansible servers -m ping
node1.kosecurity.in | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
node2.kosecurity.in | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
File Transfer
Ansible client -m copy -a “src = /etc/yum.conf dest = /tmp/yum.conf”
copy yum.conf file to all client system
install package
ansible client -m yum -a “name=vsftpd state=present”
or
Without using module yum install vsftpd package
ansible client -a “yum install vsftpd -y “
node2.kosecurity.in | SUCCESS => {
“changed”: false,
“msg”: “”,
“rc”: 0,
“results”: [
“vsftpd-3.0.2-22.el7.x86_64 providing vsftpd is already installed”
]
}
node1.kosecurity.in | SUCCESS => {
“changed”: false,
“msg”: “”,
“rc”: 0,
“results”: [
“vsftpd-3.0.2-22.el7.x86_64 providing vsftpd is already installed”
]
}

2 Comments

  1. ansible myhost -i all_hosts -m command -a “tail -29 /etc/group” > group_output

    ansible command for cat multiple host /etc/group file and output save in group_output file

Leave a Reply

Your email address will not be published.


*