Wednesday, September 21, 2022

Ansible Adhoc Command

 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"



ansible all -m ping -- > Check connectivity between master and worker nodes

ansible all -m setup -- > collect ansible facts of worker nodes

ansible all -m file -a "dest=/home/ansadmin/test-file state=directory"  -- > Create new directory on worker machine

ansible all -m file -a "dest=/home/ansadmin/test-file state=absent" -- > Delete the directory from worker machine

ansible all -m shell -a "uptime"

ansible all -m shell -a "df -h "

ansible all -m shell -a "mkdir test-server"

ansible all -m shell -a "rmdir test-server"

ansible all -m copy -a "src=/etc/ansible/sample.txt dest=/home/ansadmin" --> copy file from source to destination(remote server)

ansible all -m yum -a "name=httpd state=present" -b -- > Install a software (httpd) on remote machine

ansible all -m service -a "name=httpd state=started" -b -- > start the service on worker node

ansible all -m user -a "name=vikas" -b --> Create a new user

ansible all -m user -a "name=vikas state=absent" -b --> delete the user

ansible all -a "/sbin/reboot" -b  --> reboot command

ansible all -a "free -m" all

ansible all  -a "df -hT -m" all

ansible all  -m command  -a "uptime" all

ansible all -m shell  -a "free -m" all

ansible all -m shell  -a "cat /etc/passwd" all

ansible all  -m apt  -a "name=nginx  state=present" --become  all

ansible all -m apt  -a "name=nginx  state=absent" --become  all

ansible all  -m service -a "name=nginx  state=started" --become  all

ansible all  -m service -a "name=nginx  state=stopped" --become  all

ansible all  -m service -a "name=nginx  state=restarted" --become  all

ansible all -m file -a "path=/home/ubuntu/ansible state=directory" all

ansible all -m file -a "path=/home/ubuntu/sample.txt  state=touch" all

ansible all -m copy -a "src=/etc/hosts dest=/opt/hosts" all --become

ansible all -m group -a "name=unix state=present" all --become

ansible all -m group -a "name=unix state=absent" all --become

ansible all -m user -a "name=kajal state=present" all --become

ansible all -m user -a "name=kajal state=absent" all --become

ansible all   -m user -a "name=archana group=unix" all --become

ansible all -m shell -a "touch /home/ubuntu/file1.txt" all  --become

ansible all   -m user -a "name=archana password=unix@123" all --become

ansible allt -m shell -a "systemctl status sshd" all  --become

No comments:

Post a Comment

Sample Game App Deployment on EKS cluster

 https://padmakshi.medium.com/setting-up-an-eks-cluster-and-deploying-a-game-application-a-step-by-step-guide-08790e0be117