EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Ansible Commands

Home » Software Development » Software Development Tutorials » Ansible Tutorial » Ansible Commands

Ansible Commands

Introduction to Ansible Commands

In this Topic, we are going to learn about the Ansible Commands. As Ansible is an engine that automates the deployment of the application, cloud provisioning, etc. It uses a playbook for archiving the job automation process and the playbook is designed on top of easy and flexible also human-readable format languages like YAML etc. It mostly involves multitier deployment. It connects with nodes through a secured shell host which states that this setup is built demons.

Basic Ansible Commands

Below are mentioned the basic commands:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

  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

  • The same role has to be applied for more than one operation for efficient functioning.
  • Ansible tasks must always be named.
  • YAML tasks must be largely used.
  • Variables must also be documented.
  • Use assert to bail early in case of error.
  • Write meaningful error messages.
  • Ansible allows declaring playbooks without their name

Eg:

hosts: local
tasks:
– user:
name: Test1
state: past
groups: group1

  • Asserts in ansible can be used in order to validate each and every parameter.

Eg:

name: “Validate is a number, > 0”
assert:
that:
– “{{ version | int }} > 0”
msg: “‘version’ should be a number and > 0, is \”{{version}}\””

  • Templates are mainly used to create or modify files that have small parameters at the destination. Tags must be used in moderation. When a role is written tags can be used to filter tasks in runtime. This helps to imply runtime deployments. Two key problems in these kinds of ansible are below,
  • The same tag can be used over and over in all of your roles and collide with each other, preventing you from using exactly the tag you want to use this dispersal of tags makes it difficult to understand exactly what they do.
  • He determining the exact output is a complex task

Conclusion

Ansible commands allow you to perform software provisioning and configuration management tasks in a very structured and optimized method.it also holds a strong hand in platform support and cloud integration methods.

Popular Course in this category
All in One Software Development Bundle (600+ Courses, 50+ projects)600+ Online Courses | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (3,144 ratings)
Course Price

View Course

Related Courses
Linux Training Program (16 Courses, 3+ Projects)Kali Linux Training (3 Courses, 3+ Projects)Red Hat Linux Training Program (4 Courses, 1+ Projects)

Recommended Articles

This has been a guide to Ansible Commands. Here we have discussed basic as well as advanced Ansible Commands and some immediate Commands. You may also look at the following article to learn more –

  1. Tableau Commands
  2. MongoDB Commands
  3. Architecture of Ansible
  4. Ansible Versions

All in One Software Development Bundle (600+ Courses, 50+ projects)

600+ Online Courses

3000+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Ansible Tutorial
  • Ansible Basics
    • What is Ansible
    • Is Ansible free
    • How to Install Ansible
    • Ansible Versions
    • Ansible Architecture
    • Ansible Commands
    • Ansible ad-hoc Commands
    • Ansible Playbooks
    • Ansible Roles
    • Ansible Tags
    • Ansible Ping
    • Ansible Apt
    • Ansible Facts
    • Ansible Tower
    • Ansible Galaxy
    • Ansible Handlers
    • Ansible Loop
    • Ansible Block
    • Ansible Conditional
    • Ansible YAML
    • Ansible Debug
    • Ansible Synchronize
    • Ansible Template
    • Ansible group_vars
    • Ansible Lookup
    • Ansible File Module
    • Ansible Yum Module
    • Ansible Shell Module
    • Ansible lineinfile
    • Ansible Service Module
    • Ansible User Module
    • Ansible Windows Modules
    • ansible-doc
    • Ansible Filters
    • Ansible Add User to Group
    • Ansible Register
    • Ansible Set Fact
    • Ansible Hosts File
    • Ansible add_host
    • Ansible Collections
    • Ansible with_items
    • Ansible Replace Line in File
    • Ansible inventory_hostname
    • Ansible Dynamic Inventory
    • Ansible local_action
    • Ansible Firewalld
    • Ansible Unarchive
    • Ansible Sudo
    • Ansible Create Directory
    • Ansible Reboot
    • Ansible wait_for
    • Ansible run_once
    • Ansible Authorized_key
    • Ansible Interview Questions

Related Courses

Linux Training Course

Kali Linux Training

Red Hat Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - All in One Software Development Bundle (600+ Courses, 50+ projects) Learn More