Learn about your environment
ansible [group] -a “hostname”
ansible [group] -a “date”
ansible [group] -a “ free -m”
(-a MODULE_ARGS, –args=MODULE_ARGS module arguments)
Make changes using Ansible modules
ansible [group] -s -m yum -a “name=ntp state=present”
-m MODULE_NAME, –module-name=MODULE_NAME
-s, –sudo run operations with sudo (nopasswd)
ansible [group] -s -m service -a “name=ntpd state=started\
enabled=yes”
ansible [group] -s -a “service ntpd start”
Configure Application Servers
ansible app -s -m yum -a “name=MySQL-python state=present”
ansible app -s -m yum -a “name=python-setuptools state=present”
ansible app -s -m easy_install -a “name=django state=present”
Configure Database Server
ansible db -s -m yum -a “name=mariadb-server state=present”
ansible db -s -m service -a “name=mariadb state=started enabled=yes”
ansible db -s -a “firewall-cmd –permanent –add-port=3306/tcp”
Manage Groups and Users
ansible app -s -m group -a “name=admin state=present”
ansible app -s -m user -a “name=johndoe group=admin createhome=yes”
ansible app -s -m user -a “name=johndoe state=absent remove=yes”
Manage packages
ansible app -s -m package -a “name=git state=present”
Get information on file
ansible app -m stat -a “path=/etc/hosts”
Copy a file
ansible app -m copy -a “scr=/etc/hosts dest=/tmp/hosts”
Receive file from server
ansible app -s -m fetch -a “scr=/etc/hosts dest=/tmp”
Create directory and symlink
ansible app -m file -a “dest=/tmp/dir mode=644 state=directory”
ansible app -m file -a “scr=/tmp/dir dest=/dest/symlink owner=root group=root state=link”
Delete file
ansible app -m file -a “dest=/tmp/test state=absent”