Ansible Commands

Ansible Commands
Techiio-author
Written by Nilima PaulJanuary 15, 2022
7 min read
Ansible
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Techiio-author
Nilima Paul

Technology Security Analyst

We will know in this article, what's the Ansible Commands.

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:

  1. Verify connectivity of host: # ansible <group> -m -ping
  2. Rebooting host systems: #ansible <group> -a “/sbin/reboot”
  3. Creating a new user: # ansible <group> -m user -a “name=ansible password=<encrypted password>”
  4. User Deletion: # ansible <group> -m user -a “name=ansible state=absent”
  5. Permissions changing: # ansible <group> -m file -a “dest=/home/ansible/file1.txt mode=777”
  6. Verify package installation with update: # ansible <group> -m yum -a “name=httpd state=latest”
  7. Verify package installation without an update: # ansible <group> -m yum -a “name= httpd state=present”
  8. Verify package version: # ansible <group> -m yum -a “name= httpd-1.8 state=present”
  9. Verify package installation: # ansible <group> -m yum -a “name= httpd state=absent”
  10. Display host information: # ansible <group> -m setup | less

Intermediate Ansible Commands

  1. File transfer to more than one server : # Ansible abc -m copy -a “src = /etc/yum.conf dest = /tmp/yum.conf”
  2. Rebooting more than one group servers : # Ansible abc -a “/sbin/reboot” -f 12
  3. All adhoc information on the available facts can be gathered using the below command: # Ansible all -m setup
  4. Help option on the available roles : # ansible-galaxy -h
  5. Set a timeout in ansible : # ansible all -a “/usr/bin/scrptat” -B 2600 -P 0
  6. Generate only ansible fact for one host : #ansible <host> -m setup -a ‘filter=ansible_eth*’
  7. Verify package installation with update : # ansible <group> -m yum -a “name=httpd state=latest”
  8. Saving all the facts in a temporary directory : # ansible all -m setup –tree /tmp/facts
  9. Synopsis to Run ansible playbook : # ansible-playbook [options] playbook.yml [playbook2 …]
  10. Eg: # ansible-playbook –check playbook_a.tml
  11. 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

Ansible
Ansible Commands
python
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-author
Nilima Paul
Technology Security Analyst
Techiio-followerTechiio-followerTechiio-follower
201 Blog Posts
0 Discussion Threads
Trending Technologies
15
Software40
DevOps46
Frontend Development24
Backend Development20
Server Administration17
Linux Administration26
Data Center24
Sentry24
Terraform23
Ansible83
Docker70
Penetration Testing16
Kubernetes21
NGINX20
JenkinsX17
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance