-
Notifications
You must be signed in to change notification settings - Fork 3
/
Ansible-Adhoc-Commands.txt
59 lines (33 loc) · 1.28 KB
/
Ansible-Adhoc-Commands.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Install Ansible:
-------------------
sudo yum install epel-release
sudo yum install python-pip
yum install ansible
Create SSH Connection:
------------------------
ssh-keygen
Press enter for all questions. The public and private key will be created in the location : /root/.ssh/id_rsa
Run the below command to copy the key to other machines.
ssh-copy-id user@ip
eg: ssh-copy-id [email protected]
Ansible Modules:
-------------------------
Ping Module:
ansible testservers -m ping
File module: Creating and deleting directory
ansible testservers -m file -a "dest=/root/file state=directory"
ansible testservers -m file -a "dest=/root/file mode=755 owner=root group=root state=directory"
ansible testservers -m file -a "dest=/root/file state=absent"
Copy Module:
ansible testservers -m copy -a "src=/root/file/text.txt dest=/root/"
Shell Module:
ansible testservers -m shell -a "mkdir test"
Yum Module:
ansible testservers -m yum -a "name=wget state=present"
ansible testservers -m yum -a "name=httpd state=present"
Service Module:
ansible testservers -m service -a "name=httpd state=restarted"
ansible testservers -m service -a "name=httpd state=started"
ansible testservers -m service -a "name=httpd state=stopped"
Restarting the servers:
ansible testservers -a "/sbin/reboot"