Ansible Adhoc Commands in Linux


Where 
-m = Module name
-a = allow parameters
-u = username


ansible 127.0.0.1 -m file -a "dest=/opt/a.txt mode=600 state=touch"
ansible 127.0.0.1 -m file -a "dest=/opt/a.txt mode=600 state=touch"
ansible 127.0.0.1 -m file -a "dest=/opt/a.txt mode=600 state=touch owner=ec2-user"
ansible 127.0.0.1 -m file -a "dest=/opt/b.txt mode=755 state=touch owner=ec2-user"
ansible 127.0.0.1 -m file -a "dest=/opt/c.txt mode=755 state=touch owner=ec2-user"
ansible 127.0.0.1 -m file -a "dest=/opt/bmc.txt mode=755 owner=ec2-user"

ansible localhost -m file -a "dest=/opt/bmcdir mode=755 owner=ec2-user group=ec2-user state=directory"

ansible 127.0.0.1 -m yum -a "name=httpd state=present"
ansible 127.0.0.1 -m yum -a "name=httpd state=absent"

ansible 127.0.0.1 -m service -a "name=httpd state=started"
ansible 127.0.0.1 -m service -a "name=httpd state=stopped"

ansible 127.0.0.1 -m command -a "/bin/yum update -y"
ansible 127.0.0.1 -a "/bin/yum update -y"

ansible 127.0.0.1 -m copy -a "src=/opt/index.html dest=/var/www/html/index.html"

ansible 127.0.0.1 -m setup

# Commands used in Hands-On-Ansible Mod5 Exercise 1

# Install Apache
$ ansible webservers -i inventory -m yum -a "name=httpd state=present" --sudo

# Start Apache
$ ansible webservers -i inventory -m service -a "name=httpd enabled=yes state=started" --sudo

# Install MySQL
$ ansible dbservers -i inventory -m yum -a "name=mysql-server state=present" --sudo

# Start MySQL
$ ansible dbservers -i inventory -m service -a "name=mysqld enabled=yes state=started" --sudo

# Stop IPTables on all systems
$ ansible webservers:dbservers -i inventory -m service -a "name=iptables enabled=no state=stopped" --sudo

$ ansible servers -a "/sbin/reboot" 

$ ansible all -m user -a "name=foo password="

$ ansible webservers -m git -a "repo=https://foo.example.org/repo.git dest=/srv/myapp version=HEAD"

$ ansible all -m user -a "name=foo state=absent"