Ansible-palybooks

mohammedrafi@NOC-RAFI:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/mohammedrafi/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/mohammedrafi/.ssh/id_rsa.
Your public key has been saved in /home/mohammedrafi/.ssh/id_rsa.pub.
The key fingerprint is:
33:b8:4d:8f:95:bc:ed:1a:12:f3:6c:09:9f:52:23:d0 mohammedrafi@NOC-RAFI
The key’s randomart image is:
+–[ RSA 2048]—-+
| |
| . |
| . E |
| o . . |
| . S * |
| + / * |
| . = @ . |
| + o |
| … |
+—————–+
mohammedrafi@NOC-RAFI:~$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCpEZIWC8UGJXA5uGDRj6vUd5KlwIvE0cat3opG4ZUajmrZU382PbdO3JG6DJa3beZXylYSOYeKtRVT9DxbeKgeTKQ4m8uamM81NAMRf0ZaiqSsZ9r56h1urlJCfD4y5nXwnUTvoBzZpTvTYwcevBzpNcI/VnBIgpcKQWJq11iHHrcmybbFreujgotHg1XUwCv9BdpXbPnA50XbUyX97uqCE9EzIk7WnSNpTtsmASxMPSWoHB9seOas1mq7UBKo7Xfu7qaJJLIEnMisBLKHPb0hM23BNV2SiacJEpHSB5eJKULtMGDej38HbmBsQI3u+lzcWSRppDIt6BvO05brW5C5 mohammedrafi@NOC-RAFI

copy the key to ansible deployment sever-host for password less auth

mohammedrafi@NOC-RAFI:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 NOC-RAFI
104.198.143.3 ansible
mohammedrafi@NOC-RAFI:~$ ssh ansible
Last login: Wed Jan 18 02:51:09 2017 from 115.113.77.105
[mohammedrafi@ansible ~]$

——————————-
[mohammedrafi@ansible ~]$ sudo vim /etc/ansible/hosts
[example]
104.197.180.130
[web]
104.197.133.121
——————————-
[mohammedrafi@ansible ~]$ vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.128.0.2 ansible.c.rich-operand-154505.internal ansible # Added by Google
169.254.169.254 metadata.google.internal # Added by Google
104.197.180.130 ansible1
104.197.133.121 ansible2
104.198.143.3 ansible

——————————-
[mohammedrafi@ansible ~]$ ansible -m ping example
104.197.180.130 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
——————————-
[mohammedrafi@ansible ~]$ ansible -m ping web
104.197.133.121 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}

——————————-
[mohammedrafi@ansible ~]$ ansible -m ping all -u mohammedrafi
104.197.180.130 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
104.197.133.121 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
——————————-
[mohammedrafi@ansible ~]$ ansible -m ping all -u root
104.197.180.130 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).\r\n”,
“unreachable”: true
}
104.197.133.121 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).\r\n”,
“unreachable”: true
}
——————————-
[mohammedrafi@ansible ~]$ ansible -m ping all -b
104.197.180.130 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
104.197.133.121 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
——————————-
[mohammedrafi@ansible ~]$ ansible -s -m ping all
104.197.180.130 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
104.197.133.121 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
——————————-
[mohammedrafi@ansible ~]$ vim playbook1.yml

– hosts: all
tasks:
– name: installing telnet package
yum: name=telnet state=present

[mohammedrafi@ansible ~]$ ansible-playbook playbook1.yml

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [104.197.133.121]
ok: [104.197.180.130]

TASK [installing telnet package] ***********************************************
fatal: [104.197.180.130]: FAILED! => {“changed”: true, “failed”: true, “msg”: “You need to be root to perform this command.\n”, “rc”: 1, “results”: [“Loaded plugins: fastestmirror\n”]}
fatal: [104.197.133.121]: FAILED! => {“changed”: true, “failed”: true, “msg”: “You need to be root to perform this command.\n”, “rc”: 1, “results”: [“Loaded plugins: fastestmirror\n”]}
to retry, use: –limit @/home/mohammedrafi/playbook1.retry

PLAY RECAP *********************************************************************
104.197.133.121 : ok=1 changed=0 unreachable=0 failed=1
104.197.180.130 : ok=1 changed=0 unreachable=0 failed=1

[mohammedrafi@ansible ~]$ ansible-playbook playbook1.yml -b

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [104.197.133.121]
ok: [104.197.180.130]

TASK [installing telnet package] ***********************************************
changed: [104.197.180.130]
changed: [104.197.133.121]

PLAY RECAP *********************************************************************
104.197.133.121 : ok=2 changed=1 unreachable=0 failed=0
104.197.180.130 : ok=2 changed=1 unreachable=0 failed=0
——————————-
[mohammedrafi@ansible ~]$ vim playbook2.yml

– hosts: all
tasks:
– name: inatalling nfs package
yum: name=nfs-utils state=present

– name: statrting nfs service
service: name=nfs state=started enabled=yes

[mohammedrafi@ansible ~]$ ansible-playbook playbook2.yml –syntax-check

playbook: playbook2.yml
[mohammedrafi@ansible ~]$ ansible-playbook playbook2.yml –check

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [104.197.133.121]
ok: [104.197.180.130]

TASK [inatalling nfs package] **************************************************
changed: [104.197.180.130]
changed: [104.197.133.121]

TASK [statrting nfs service] ***************************************************
fatal: [104.197.133.121]: FAILED! => {“changed”: false, “failed”: true, “msg”: “Could not find the requested service \”‘nfs’\”: “}
fatal: [104.197.180.130]: FAILED! => {“changed”: false, “failed”: true, “msg”: “Could not find the requested service \”‘nfs’\”: “}
to retry, use: –limit @/home/mohammedrafi/playbook2.retry

PLAY RECAP *********************************************************************
104.197.133.121 : ok=2 changed=1 unreachable=0 failed=1
104.197.180.130 : ok=2 changed=1 unreachable=0 failed=1

————————
[mohammedrafi@ansible ~]$ ansible-playbook playbook2.yml -b

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [104.197.133.121]
ok: [104.197.180.130]

TASK [inatalling nfs package] **************************************************
changed: [104.197.133.121]
changed: [104.197.180.130]

TASK [statrting nfs service] ***************************************************
changed: [104.197.133.121]
changed: [104.197.180.130]

PLAY RECAP *********************************************************************
104.197.133.121 : ok=3 changed=2 unreachable=0 failed=0
104.197.180.130 : ok=3 changed=2 unreachable=0 failed=0
—————-

Run again and again same play book configuration remains same as Idempotent
[mohammedrafi@ansible ~]$ ansible-playbook playbook2.yml -b

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [104.197.133.121]
ok: [104.197.180.130]

TASK [inatalling nfs package] **************************************************
ok: [104.197.133.121]
ok: [104.197.180.130]

TASK [statrting nfs service] ***************************************************
ok: [104.197.133.121]
ok: [104.197.180.130]

PLAY RECAP *********************************************************************
104.197.133.121 : ok=3 changed=0 unreachable=0 failed=0
104.197.180.130 : ok=3 changed=0 unreachable=0 failed=0

=================================================
[mohammedrafi@ansible ~]$ ansible all -a “service nfs status” -b
104.197.180.130 | SUCCESS | rc=0 >>
● nfs-server.service – NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
Active: active (exited) since Wed 2017-01-18 04:14:18 UTC; 2min 13s ago
Process: 12036 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Process: 12035 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Main PID: 12036 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/nfs-server.service

104.197.133.121 | SUCCESS | rc=0 >>
● nfs-server.service – NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
Active: active (exited) since Wed 2017-01-18 04:14:18 UTC; 2min 13s ago
Process: 6738 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Process: 6737 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Main PID: 6738 (code=exited, status=0/SUCCESS)
Memory: 0B
CGroup: /system.slice/nfs-server.service
—————————————————
[mohammedrafi@ansible ~]$ vim playbook3.yml

– hosts: all
become: yes
tasks:
– name: Install Apache.
yum: name={{ item }} state=present
with_items:
– httpd
– httpd-devel
– name: Copy configuration files.
copy:
src: “{{ item.src }}”
dest: “{{ item.dest }}”
owner: root
group: root
mode: 0644
with_items:
– src: “httpd.conf”
dest: “/etc/httpd/conf/httpd.conf”
– src: “httpd-vhosts.conf”
dest: “/etc/httpd/conf/httpd-vhosts.conf”
– name: Make sure Apache is started now and at boot.
service: name=httpd state=started enabled=yes
[mohammedrafi@ansible ~]$ ls -l
total 40
-rw-r–r–. 1 mohammedrafi mohammedrafi 11753 Jan 18 06:27 httpd.conf
-rw-r–r–. 1 mohammedrafi mohammedrafi 824 Jan 18 06:27 httpd-vhosts.conf

[mohammedrafi@ansible ~]$ ansible-playbook playbook3.yml

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [104.197.133.121]
ok: [104.197.180.130]

TASK [Install Apache.] *********************************************************
changed: [104.197.180.130] => (item=[u’httpd’, u’httpd-devel’])
changed: [104.197.133.121] => (item=[u’httpd’, u’httpd-devel’])

TASK [Copy configuration files.] ***********************************************
ok: [104.197.133.121] => (item={u’dest’: u’/etc/httpd/conf/httpd.conf’, u’src’: u’httpd.conf’})
ok: [104.197.180.130] => (item={u’dest’: u’/etc/httpd/conf/httpd.conf’, u’src’: u’httpd.conf’})
ok: [104.197.133.121] => (item={u’dest’: u’/etc/httpd/conf/httpd-vhosts.conf’, u’src’: u’httpd-vhosts.conf’})
ok: [104.197.180.130] => (item={u’dest’: u’/etc/httpd/conf/httpd-vhosts.conf’, u’src’: u’httpd-vhosts.conf’})

TASK [Make sure Apache is started now and at boot.] ****************************
changed: [104.197.133.121]
changed: [104.197.180.130]

PLAY RECAP *********************************************************************
104.197.133.121 : ok=4 changed=2 unreachable=0 failed=0
104.197.180.130 : ok=4 changed=2 unreachable=0 failed=0

playbook1playbook2
[mohammedrafi@ansible ~]$ sudo vim /etc/ansible/hosts
[example]
104.197.180.130
[web]
104.197.133.121
[multi:children]
example
web

[mohammedrafi@ansible ~]$ ansible multi -m ping
104.197.180.130 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
104.197.133.121 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
—————————————————

[mohammedrafi@ansible ~]$ ansible multi -a hostname
104.197.133.121 | SUCCESS | rc=0 >>
ansible2.c.rich-operand-154505.internal

104.197.180.130 | SUCCESS | rc=0 >>
ansible1.c.rich-operand-154505.internal
—————————————-
[mohammedrafi@ansible ~]$ ansible multi -a ‘free -m’
104.197.133.121 | SUCCESS | rc=0 >>
total used free shared buff/cache available
Mem: 3700 229 1673 178 1796 2978
Swap: 0 0 0

104.197.180.130 | SUCCESS | rc=0 >>
total used free shared buff/cache available
Mem: 3700 329 265 16 3105 3031
Swap: 0 0 0
—————————————-
[mohammedrafi@ansible ~]$ ansible multi -a “du -h”
104.197.180.130 | SUCCESS | rc=0 >>
4.0K ./.ssh
56K ./.ansible/tmp/ansible-tmp-1484714028.87-63512995370206
56K ./.ansible/tmp
56K ./.ansible
0 ./.puppetlabs/var
0 ./.puppetlabs/etc
0 ./.puppetlabs/opt/puppet
0 ./.puppetlabs/opt
0 ./.puppetlabs
80K .

104.197.133.121 | SUCCESS | rc=0 >>
4.0K ./.ssh
56K ./.ansible/tmp/ansible-tmp-1484714028.87-38086154108105
56K ./.ansible/tmp
56K ./.ansible
80K .
————————————-
[mohammedrafi@ansible ~]$ ansible multi -a ‘service httpd status’ -b
104.197.133.121 | FAILED | rc=4 >>
Redirecting to /bin/systemctl status httpd.service
Unit httpd.service could not be found.

104.197.180.130 | FAILED | rc=4 >>
Redirecting to /bin/systemctl status httpd.service
Unit httpd.service could not be found.
————————————-
[mohammedrafi@ansible ~]$ ansible multi -a ‘netstat -tlpn’ -s
104.197.133.121 | SUCCESS | rc=0 >>
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2380 0.0.0.0:* LISTEN 15329/etcd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 6736/rpc.mountd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 994/sshd
tcp 0 0 0.0.0.0:34457 0.0.0.0:* LISTEN –
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1041/master
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN –
tcp 0 0 0.0.0.0:43009 0.0.0.0:* LISTEN 6724/rpc.statd
tcp6 0 0 :::10251 :::* LISTEN 15502/kube-schedule
tcp6 0 0 :::6443 :::* LISTEN 15445/kube-apiserve
tcp6 0 0 :::2379 :::* LISTEN 15329/etcd
tcp6 0 0 :::10252 :::* LISTEN 15463/kube-controll
tcp6 0 0 :::111 :::* LISTEN 6524/rpcbind
tcp6 0 0 :::20048 :::* LISTEN 6736/rpc.mountd
tcp6 0 0 :::8080 :::* LISTEN 15445/kube-apiserve
tcp6 0 0 :::22 :::* LISTEN 994/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1041/master
tcp6 0 0 :::36474 :::* LISTEN –
tcp6 0 0 :::2049 :::* LISTEN –
tcp6 0 0 :::54309 :::* LISTEN 6724/rpc.statd

104.197.180.130 | SUCCESS | rc=0 >>
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 7715/java
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 12034/rpc.mountd
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 7715/java
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 990/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1032/master
tcp 0 0 0.0.0.0:4447 0.0.0.0:* LISTEN 7715/java
tcp 0 0 0.0.0.0:45185 0.0.0.0:* LISTEN –
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN –
tcp 0 0 0.0.0.0:9990 0.0.0.0:* LISTEN 7715/java
tcp 0 0 0.0.0.0:53095 0.0.0.0:* LISTEN 12018/rpc.statd
tcp6 0 0 :::111 :::* LISTEN 11822/rpcbind
tcp6 0 0 :::20048 :::* LISTEN 12034/rpc.mountd
tcp6 0 0 :::22 :::* LISTEN 990/sshd
tcp6 0 0 :::43255 :::* LISTEN –
tcp6 0 0 :::55927 :::* LISTEN 12018/rpc.statd
tcp6 0 0 ::1:25 :::* LISTEN 1032/master
tcp6 0 0 :::2049 :::* LISTEN –


[mohammedrafi@ansible ~]$ ansible multi -s -m yum -a “name=ntp state=present”
104.197.180.130 | SUCCESS => {
“changed”: false,
“msg”: “”,
“rc”: 0,
“results”: [
“ntp-4.2.6p5-25.el7.centos.x86_64 providing ntp is already installed”
]
}
104.197.133.121 | SUCCESS => {
“changed”: false,
“msg”: “”,
“rc”: 0,
“results”: [
“ntp-4.2.6p5-25.el7.centos.x86_64 providing ntp is already installed”
]
}

————————————–
[mohammedrafi@ansible ~]$ ansible multi -s -m service -a “name=ntpd state=started enabled=yes”
————————————–
[mohammedrafi@ansible ~]$ ntpdate
18 Jan 04:57:35 ntpdate[4532]: no servers can be used, exiting
————————————–
[mohammedrafi@ansible ~]$ ansible multi -s -a “service ntpd stop”
104.197.180.130 | SUCCESS | rc=0 >>
Redirecting to /bin/systemctl stop ntpd.service

104.197.133.121 | SUCCESS | rc=0 >>
Redirecting to /bin/systemctl stop ntpd.service
————————————–
[mohammedrafi@ansible ~]$ ansible multi -s -a “ntpdate -q 0.rhel.pool.ntp.org”
104.197.133.121 | SUCCESS | rc=0 >>
server 138.236.128.112, stratum 2, offset -0.003149, delay 0.05275
server 71.210.146.228, stratum 2, offset 0.003796, delay 0.04633
server 128.138.141.172, stratum 1, offset -0.000194, delay 0.03752
server 69.89.207.199, stratum 2, offset -0.000211, delay 0.05193
18 Jan 04:58:22 ntpdate[10370]: adjust time server 128.138.141.172 offset -0.000194 sec

104.197.180.130 | SUCCESS | rc=0 >>
server 173.230.144.109, stratum 2, offset 0.000549, delay 0.06175
server 45.127.113.2, stratum 3, offset 0.000591, delay 0.06134
server 4.53.160.75, stratum 2, offset -0.000900, delay 0.04163
server 50.116.52.97, stratum 2, offset -0.001006, delay 0.05426
18 Jan 04:58:22 ntpdate[15477]: adjust time server 4.53.160.75 offset -0.000900 sec
————————————–
[mohammedrafi@ansible ~]$ ansible example -s -m yum -a “name=MySQL-python state=present”
104.197.180.130 | SUCCESS => {
“changed”: true,
“msg”: “”,
“rc”: 0,
“results”: [
“Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: bay.uchicago.edu\n * epel: mirror.steadfast.net\n * extras: mirror.tzulo.com\n * updates: mirror.team-cymru.org\nResolving Dependencies\n–> Running transaction check\n—> Package MySQL-python.x86_64 0:1.2.5-1.el7 will be installed\n–> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n MySQL-python x86_64 1.2.5-1.el7 base 90 k\n\nTransaction Summary\n================================================================================\nInstall 1 Package\n\nTotal download size: 90 k\nInstalled size: 284 k\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : MySQL-python-1.2.5-1.el7.x86_64 1/1 \n Verifying : MySQL-python-1.2.5-1.el7.x86_64 1/1 \n\nInstalled:\n MySQL-python.x86_64 0:1.2.5-1.el7 \n\nComplete!\n”
]
}

[mohammedrafi@ansible ~]$ ansible example -s -m yum -a “name=python-setuptools state=present”
104.197.180.130 | SUCCESS => {
“changed”: false,
“msg”: “”,
“rc”: 0,
“results”: [
“python-setuptools-0.9.8-4.el7.noarch providing python-setuptools is already installed”
]
}

[mohammedrafi@ansible ~]$ ansible example -s -m easy_install -a “name=django state=present”
104.197.180.130 | SUCCESS => {
“binary”: “/bin/easy_install”,
“changed”: true,
“name”: “django”,
“virtualenv”: null
}
————————————–
[mohammedrafi@ansible ~]$ ansible example -s -m user -a “name=admin state=present”
104.197.180.130 | SUCCESS => {
“changed”: true,
“comment”: “”,
“createhome”: true,
“group”: 1004,
“home”: “/home/admin”,
“name”: “admin”,
“shell”: “/bin/bash”,
“state”: “present”,
“system”: false,
“uid”: 1003
}
[mohammedrafi@ansible ~]$ ansible example -s -m group -a “name=admin state=present”
104.197.180.130 | SUCCESS => {
“changed”: false,
“gid”: 1004,
“name”: “admin”,
“state”: “present”,
“system”: false
}
[mohammedrafi@ansible ~]$ ansible example -s -m user -a “name=first group=admin state=present”
104.197.180.130 | SUCCESS => {
“changed”: true,
“comment”: “”,
“createhome”: true,
“group”: 1004,
“home”: “/home/first”,
“name”: “first”,
“shell”: “/bin/bash”,
“state”: “present”,
“system”: false,
“uid”: 1004
}
[mohammedrafi@ansible ~]$ ansible example -a “tail /etc/passwd”
104.197.180.130 | SUCCESS | rc=0 >>
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
mohammedrafi:x:1000:1001::/home/mohammedrafi:/bin/bash
rafishaik494:x:1001:1002::/home/rafishaik494:/bin/bash
jboss:x:1002:1003::/home/jboss:/bin/bash
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
admin:x:1003:1004::/home/admin:/bin/bash
first:x:1004:1004::/home/first:/bin/bash

[mohammedrafi@ansible ~]$ ansible example -a “tail /etc/shadow”
104.197.180.130 | FAILED | rc=1 >>
tail: cannot open ‘/etc/shadow’ for reading: Permission denied

[mohammedrafi@ansible ~]$ ansible example -a “tail /etc/shadow” -b
104.197.180.130 | SUCCESS | rc=0 >>
systemd-network:!!:17176::::::
tss:!!:17176::::::
mohammedrafi:*:17178:0:99999:7:::
rafishaik494:*:17178:0:99999:7:::
jboss:!!:17182:0:99999:7:::
rpc:!!:17184:0:99999:7:::
rpcuser:!!:17184::::::
nfsnobody:!!:17184::::::
admin:!!:17184:0:99999:7:::
first:!!:17184:0:99999:7:::
——————————–

[mohammedrafi@ansible ~]$ ansible example -m stat -a “path=/etc/hosts”
104.197.180.130 | SUCCESS => {
“changed”: false,
“stat”: {
“atime”: 1484635843.2532218,
“checksum”: “5fed7929fb7be9b1046252b6b7e0e2263fbc0738”,
“ctime”: 1484203757.175483,
“dev”: 2049,
“executable”: false,
“exists”: true,
“gid”: 0,
“gr_name”: “root”,
“inode”: 240,
“isblk”: false,
“ischr”: false,
“isdir”: false,
“isfifo”: false,
“isgid”: false,
“islnk”: false,
“isreg”: true,
“issock”: false,
“isuid”: false,
“md5”: “10f391742a450d220ff00269216eff8a”,
“mode”: “0644”,
“mtime”: 1484203757.175483,
“nlink”: 1,
“path”: “/etc/hosts”,
“pw_name”: “root”,
“readable”: true,
“rgrp”: true,
“roth”: true,
“rusr”: true,
“size”: 297,
“uid”: 0,
“wgrp”: false,
“woth”: false,
“writeable”: false,
“wusr”: true,
“xgrp”: false,
“xoth”: false,
“xusr”: false
}
}

========================================
[mohammedrafi@ansible ~]$ ansible multi -m copy -a “src=/etc/hosts dest=/tmp/hosts”
104.197.180.130 | SUCCESS => {
“changed”: true,
“checksum”: “08aa54eecc8a866b53d38351ea72e5bb97718005”,
“dest”: “/tmp/hosts”,
“gid”: 1001,
“group”: “mohammedrafi”,
“md5sum”: “72ff7a2085a5186d0cab74f14bae1483”,
“mode”: “0664”,
“owner”: “mohammedrafi”,
“secontext”: “unconfined_u:object_r:user_home_t:s0”,
“size”: 369,
“src”: “/home/mohammedrafi/.ansible/tmp/ansible-tmp-1484717608.47-178441141048946/source”,
“state”: “file”,
“uid”: 1000
}
104.197.133.121 | SUCCESS => {
“changed”: true,
“checksum”: “08aa54eecc8a866b53d38351ea72e5bb97718005”,
“dest”: “/tmp/hosts”,
“gid”: 1001,
“group”: “mohammedrafi”,
“md5sum”: “72ff7a2085a5186d0cab74f14bae1483”,
“mode”: “0664”,
“owner”: “mohammedrafi”,
“secontext”: “unconfined_u:object_r:user_home_t:s0”,
“size”: 369,
“src”: “/home/mohammedrafi/.ansible/tmp/ansible-tmp-1484717608.85-272034831244848/source”,
“state”: “file”,
“uid”: 1000
}
==========================================
[mohammedrafi@ansible ~]$ ansible multi -s -m fetch -a “src=/etc/hosts dest=/tmp”
104.197.180.130 | SUCCESS => {
“changed”: true,
“checksum”: “5fed7929fb7be9b1046252b6b7e0e2263fbc0738”,
“dest”: “/tmp/104.197.180.130/etc/hosts”,
“md5sum”: “10f391742a450d220ff00269216eff8a”,
“remote_checksum”: “5fed7929fb7be9b1046252b6b7e0e2263fbc0738”,
“remote_md5sum”: null
}
104.197.133.121 | SUCCESS => {
“changed”: true,
“checksum”: “0b24c9ee4a888defdf6769d5e72f65761e882f1f”,
“dest”: “/tmp/104.197.133.121/etc/hosts”,
“md5sum”: “e2dd8ef8a5f58f35d7a3f3dce7f2f2bf”,
“remote_checksum”: “0b24c9ee4a888defdf6769d5e72f65761e882f1f”,
“remote_md5sum”: null
}
============================================
[mohammedrafi@ansible ~]$ ls -l /tmp/
total 16
drwxrwxr-x. 3 mohammedrafi mohammedrafi 16 Jan 18 05:34 104.197.133.121
drwxrwxr-x. 3 mohammedrafi mohammedrafi 16 Jan 18 05:34 104.197.180.130

[mohammedrafi@ansible ~]$ cat /tmp/104.197.180.130/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.128.0.3 ansible1.c.rich-operand-154505.internal ansible1 # Added by Google
169.254.169.254 metadata.google.internal # Added by Google
==========================================
[mohammedrafi@ansible ~]$ ansible multi -m file -a “dest=/tmp/test mode=644 state=directory”
104.197.180.130 | SUCCESS => {
“changed”: true,
“gid”: 1001,
“group”: “mohammedrafi”,
“mode”: “0644”,
“owner”: “mohammedrafi”,
“path”: “/tmp/test”,
“secontext”: “unconfined_u:object_r:user_tmp_t:s0”,
“size”: 6,
“state”: “directory”,
“uid”: 1000
}
104.197.133.121 | SUCCESS => {
“changed”: true,
“gid”: 1001,
“group”: “mohammedrafi”,
“mode”: “0644”,
“owner”: “mohammedrafi”,
“path”: “/tmp/test”,
“secontext”: “unconfined_u:object_r:user_tmp_t:s0”,
“size”: 6,
“state”: “directory”,
“uid”: 1000
}
===========================================
[mohammedrafi@ansible ~]$ ansible multi -s -m file -a “dest=/tmp/test mode=644 owner=root state=directory”
104.197.133.121 | SUCCESS => {
“changed”: true,
“gid”: 1001,
“group”: “mohammedrafi”,
“mode”: “0644”,
“owner”: “root”,
“path”: “/tmp/test”,
“secontext”: “unconfined_u:object_r:user_tmp_t:s0”,
“size”: 6,
“state”: “directory”,
“uid”: 0
}
104.197.180.130 | SUCCESS => {
“changed”: true,
“gid”: 1001,
“group”: “mohammedrafi”,
“mode”: “0644”,
“owner”: “root”,
“path”: “/tmp/test”,
“secontext”: “unconfined_u:object_r:user_tmp_t:s0”,
“size”: 6,
“state”: “directory”,
“uid”: 0
}
================================================
[mohammedrafi@ansible ~]$ ansible multi -s -B 3600 -a “yum -y update”
=================================================
[mohammedrafi@ansible ~]$ ansible 104.197.180.130 -s -a “tail /var/log/messages”
104.197.180.130 | SUCCESS | rc=0 >>
Jan 18 05:41:03 ansible1 ansible-async_wrapper.py: Return async_wrapper task started.
Jan 18 05:41:03 ansible1 ansible-async_wrapper.py: Starting module and watcher
Jan 18 05:41:03 ansible1 ansible-async_wrapper.py: Start watching 18305 (3600)
Jan 18 05:41:03 ansible1 ansible-async_wrapper.py: Start module (18305)
Jan 18 05:41:03 ansible1 ansible-async_wrapper.py: Module complete (18305)
Jan 18 05:41:08 ansible1 ansible-async_wrapper.py: Done in kid B.
Jan 18 05:42:04 ansible1 systemd-logind: Removed session 180.
Jan 18 05:42:04 ansible1 systemd: Started Session 181 of user mohammedrafi.
Jan 18 05:42:04 ansible1 systemd-logind: New session 181 of user mohammedrafi.
Jan 18 05:42:04 ansible1 systemd: Starting Session 181 of user mohammedrafi.
=================================================
[mohammedrafi@ansible ~]$ ansible multi -s -m shell -a “tail /var/log/messages | grep ansible-command | wc -l”
104.197.180.130 | SUCCESS | rc=0 >>
0

104.197.133.121 | SUCCESS | rc=0 >>
0
=================================
[mohammedrafi@ansible ~]$ ansible example -s -m git -a “repo=git://example.com/path/to/repo.git dest=/opt/myapp update=yes version=1.2.4”
104.197.180.130 | FAILED! => {
“changed”: false,
“failed”: true,
“msg”: “Failed to find required executable git”
}
[mohammedrafi@ansible ~]$ ansible example -s -m yum -a “name=git state=present”
104.197.180.130 | SUCCESS => {
“changed”: true,
“msg”: “”,
“rc”: 0,
“results”: [
“Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: bay.uchicago.edu\n * epel: mirror.steadfast.net\n * extras: mirror.tzulo.com\n * updates: mirror.team-cymru.org\nResolving Dependencies\n–> Running transaction check\n—> Package git.x86_64 0:1.8.3.1-6.el7_2.1 will be installed\n–> Processing Dependency: perl-Git = 1.8.3.1-6.el7_2.1 for package: git-1.8.3.1-6.el7_2.1.x86_64\n–> Processing Dependency: perl(Term::ReadKey) for package: git-1.8.3.1-6.el7_2.1.x86_64\n–> Processing Dependency: perl(Git) for package: git-1.8.3.1-6.el7_2.1.x86_64\n–> Processing Dependency: perl(Error) for package: git-1.8.3.1-6.el7_2.1.x86_64\n–> Processing Dependency: libgnome-keyring.so.0()(64bit) for package: git-1.8.3.1-6.el7_2.1.x86_64\n–> Running transaction check\n—> Package libgnome-keyring.x86_64 0:3.8.0-3.el7 will be installed\n—> Package perl-Error.noarch 1:0.17020-2.el7 will be installed\n—> Package perl-Git.noarch 0:1.8.3.1-6.el7_2.1 will be installed\n—> Package perl-TermReadKey.x86_64 0:2.30-20.el7 will be installed\n–> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n git x86_64 1.8.3.1-6.el7_2.1 base 4.4 M\nInstalling for dependencies:\n libgnome-keyring x86_64 3.8.0-3.el7 base 109 k\n perl-Error noarch 1:0.17020-2.el7 base 32 k\n perl-Git noarch 1.8.3.1-6.el7_2.1 base 53 k\n perl-TermReadKey x86_64 2.30-20.el7 base 31 k\n\nTransaction Summary\n================================================================================\nInstall 1 Package (+4 Dependent packages)\n\nTotal download size: 4.6 M\nInstalled size: 23 M\nDownloading packages:\n——————————————————————————–\nTotal 12 MB/s | 4.6 MB 00:00 \nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : 1:perl-Error-0.17020-2.el7.noarch 1/5 \n Installing : libgnome-keyring-3.8.0-3.el7.x86_64 2/5 \n Installing : perl-TermReadKey-2.30-20.el7.x86_64 3/5 \n Installing : git-1.8.3.1-6.el7_2.1.x86_64 4/5 \n Installing : perl-Git-1.8.3.1-6.el7_2.1.noarch 5/5 \n Verifying : perl-Git-1.8.3.1-6.el7_2.1.noarch 1/5 \n Verifying : perl-TermReadKey-2.30-20.el7.x86_64 2/5 \n Verifying : libgnome-keyring-3.8.0-3.el7.x86_64 3/5 \n Verifying : 1:perl-Error-0.17020-2.el7.noarch 4/5 \n Verifying : git-1.8.3.1-6.el7_2.1.x86_64 5/5 \n\nInstalled:\n git.x86_64 0:1.8.3.1-6.el7_2.1 \n\nDependency Installed:\n libgnome-keyring.x86_64 0:3.8.0-3.el7 perl-Error.noarch 1:0.17020-2.el7 \n perl-Git.noarch 0:1.8.3.1-6.el7_2.1 perl-TermReadKey.x86_64 0:2.30-20.el7 \n\nComplete!\n”
]
}

========================================================

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s