Introduction to Ansible Commands
In this Topic, we will find out with regards to the Ansible Commands as Ansible is a motor that computerizes the arrangement of the application, cloud provisioning, and so forth It involves a playbook for documenting the work robotization process, and the playbook is planned on top of simple and adaptable likewise intelligible configuration dialects like YAML and so forth It generally includes multitier sending. It associates with hubs through a got shell have, which expresses that this arrangement is fabricated devils.
Basic Ansible Commands
Below are mentioned the basic commands:
- Verify connectivity of host: # ansible <group> -m -ping
- Rebooting host systems: #ansible <group> -a “/sbin/reboot”
- Creating a new user: # ansible <group> -m user -a “name=ansible password=<encrypted password>”
- User Deletion: # ansible <group> -m user -a “name=ansible state=absent”
- Permissions changing: # ansible <group> -m file -a “dest=/home/ansible/file1.txt mode=777”
- Verify package installation with update: # ansible <group> -m yum -a “name=httpd state=latest”
- Verify package installation without an update: # ansible <group> -m yum -a “name= httpd state=present”
- Verify package version: # ansible <group> -m yum -a “name= httpd-1.8 state=present”
- Verify package installation: # ansible <group> -m yum -a “name= httpd state=absent”
- Display host information: # ansible <group> -m setup | less
Intermediate Ansible Commands
- File transfer to more than one server : # Ansible abc -m copy -a “src = /etc/yum.conf dest = /tmp/yum.conf”
- Rebooting more than one group servers : # Ansible abc -a “/sbin/reboot” -f 12
- All adhoc information on the available facts can be gathered using the below command: # Ansible all -m setup
- Help option on the available roles : # ansible-galaxy -h
- Set a timeout in ansible : # ansible all -a “/usr/bin/scrptat” -B 2600 -P 0
- Generate only ansible fact for one host : #ansible <host> -m setup -a ‘filter=ansible_eth*’
- Verify package installation with update : # ansible <group> -m yum -a “name=httpd state=latest”
- Saving all the facts in a temporary directory : # ansible all -m setup –tree /tmp/facts
- Synopsis to Run ansible playbook : # ansible-playbook [options] playbook.yml [playbook2 …]
- Eg: # ansible-playbook –check playbook_a.tml
- Synopsis to run ansible pull : # ansible-pull -U <repository> [options] [<playbook.yml>]
Advanced Ansible Commands
Executing commands on the remote host by using psexec models:
psexec:
hostname: 197.163.12.2
connection_username: username
connection_password: password
executable: powershell.exe
arguments: '-'
stdin: |
Write-Host Hi
Write-Error Error Message
exit
Run process asynchronously using psexec:
psexec:
hostname: server
connection_username: username
connection_password: password
executable: cmd.exe
arguments: /c rmdir C:\temp
asynchronous: yes
Case sensitive password string match:
name: Case insensitive password string match
expect:
command: passwd username
responses:
(?i)password: "MySekretPa$$word"
# you don't want to show passwords in your logs
no_log: true
Tips and Tricks to Use Ansible Commands
- A similar job must be applied for more than one activity for productive working.
- Ansible assignments should forever be named.
- YAML undertakings should be generally utilized.
- Factors should likewise be archived.
- Use declare to bail right off the bat in the event of blunder.
- Compose significant blunder messages.
- Ansible permits announcing playbooks without their name
E.g.:
has: neighborhood
errands:
- client:
name: Test1
state: past
gatherings: group1
- Affirms in Ansible can be utilized to approve every single boundary.
E.g.:
name: "Approve is a number, > 0"
affirm:
that:
- "{{ rendition | int }} > 0"
msg: "'variant' ought to be a number and > 0, is \"{{version}}\""
- Formats are for the most part used to make or alter records that have little boundaries at the objective. Labels should be utilized with some restraint. At the point when a job is composed, labels can be utilized to channel assignments in runtime. This assists with suggesting runtime organizations. Two critical issues in these sorts of ansible are beneath,
- A similar tag can be utilized again and again in your parts in general and crash into one another, keeping you from utilizing precisely the label you need to utilize this dispersal of labels makes it hard to see precisely what they do.
- He deciding the specific result is an intricate undertaking
Conclusion
Ansible orders permit you to perform programming provisioning and arrangement the executives errands in an extremely organized and advanced method.it additionally holds a solid hand in stage backing and cloud incorporation techniques