• Blog timeApr 24, 2023
  • Blog author Poonam
  • Blog CategoryCategory: DevOps Ansible Automation

We know you have heard about Ansible. It is a name that is almost impossible to ignore for those who are a part of the tech world. If you are thinking about enrolling in Ansible training and certification course, then you are already on the right track.

However, first it is best to learn all that you can about it. With this blog, we will give you an introduction to Ansible commands. Let us get started in this field to help you decide whether Ansible is the right path for you or not.

Before we dive into Ansible commands, let us introduce Ansible to you. Here is a brief introduction to his amazing IT automation engine that is all the rage right now.

 

An Introduction to Ansible

It is important to take one step at a time when it comes to learning things in the tech world. Thus, before we take you towards Ansible commands, we will take you briefly through Ansible.

Ansible is a widely known open-source IT automation engine. It automates application deployment, provisioning, orchestration, configuration management, and various other IT processes.

Professionals employ Ansible automation for

  • Installing software
  • Improving security
  • Automating daily tasks
  • Patching systems
  • Improving compliance
  • Provisioning infrastructure
  • Sharing automation across the organization

Ansible makes use of a playbook to achieve the job automation process. This playbook is designed with YAML to ensure it is easy and flexible.

 

Ansible Commands

There are hundreds of Ansible commands that you can benefit from when learned. In this blog, we will take you through a few of those. Here are the ones that will help you in your career expansion.

 

Let us get this knowledge step wise. Thus, first we will look at some of the Basic Ansible Commands.

 

Here are some Basic Ansible Commands

  • Verify connectivity of host

#ansible -m -ping

  • Creating a new user

#ansible -m user -a “name=ansible password=

  • Permissions changing

# ansible -m file -a “dest=/home/ansible/file1/txt mode=777”

  • Verify package installation without an update

# ansible -m yum -a “name=httpd state=present”

  • Verify package installation

# ansible -m yum -a “name= httpd state=absent”

  • Rebooting host systems

# ansible -a “/sbin/reboot”

  • User deletion​​​​​

# ansible -m user -a “name=ansible state=absent”

  • Verify package installation with an update

# ansible -m yum -a “name=httpd state=latest”

  • Verify package version

# ansible -m yum -a “name= httpd-1.8 state=present”

  • Display host information

# ansible -m setup I less

 

Here are some Intermediate Ansible Commands

Now that you are ahead with some of the basic Ansible commands, let us take you through some intermediate Ansible Commands. Here are the top ones to know about.

 

  • File transfer to more than one server

# Ansible abc -m copy -a “src = /etc/yum/conf dest = /tmp/yum.conf”

  • This command will help you get all ad-hoc information on the available facts

# Ansible all -m setup

  • Set a timeout in Ansible

# ansible all -a “/usr/bin/scrptat” -B 2600 -P 0

  • Verify package installation with update

# ansible -m yum -a “name=httpd state=latest”

  • Synopsis to run Ansible playbook

# ansible-playbook [options] playbook.yml [playbook2 …]

  • Reboot more than one group servers

# Ansible abc – a “/sbin/reboot” -f 12

  • Help option on the available roles

# ansible-galaxy -h

  • Generate only Ansible fact for one host

# ansible -m setup -a ‘filter=ansible_eth*’

  • Saving all the facts in a temporary directory

# ansible all -m setup -tree/tmp/facts

  • Synopsis to run Ansible pull

# ansible-pull -U [options] []

 

After you master basic and intermediate Ansible commands, it is obvious that you would want to go the next step. Thus, we are now taking you towards some Advanced Ansible Commands. Learning these is important to be called a professional in the tech field.

Once you master these, numerous opportunities will open up for you. You will be able to find a job that sits well with you and will be able to provide you the kind of career and future you deserve.

With the right Ansible training and certification program, you will become 100% job ready.  However, it does no harm to get started with the right training a litter early.

 

Here are some Advanced Ansible Commands

Let us get to know about some commonly used Advanced Ansible Commands.

 

  1. Executing a myriad of commands on the remote host by making use of the psexec model

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

 

       2. Case sensitive password string match

name: Case insentitive 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

 

       3. Run process asynchronously using psexec

Psexec

hostname: server

connection_username: username

connection_password: password

executable: cmd.exe

arguments: /c mdir C:\temp

asynchronous: yes

 

Tricks & Tips of Using Ansible Commands

When it comes to using Ansible commands, there are a lot of tips and tricks you can use. Remembering everything at all times can prove to be difficult. But with the right knowledge up your sleeves, you can ace this field.

Here are some tricks and tips of using Ansible commands.

  • It is best to apply the same role for more than one operation. This aids in promoting efficient functioning.
  • It is wise to use YAML tasks largely.
  • Using assert for early bail in the case of error is advised.
  • You can declare playbook without their names.
  • Every Ansible task must be named, always.
  • All the variable mut always be documented.
  • Writing meaningful error messages will benefit you.
  • The asserts in Ansible have a special purpose. They can be used for validating every single parameter.
  • It is wise to use templates when creating or modifying files with small parameters at the destination.
  • Tags should only be used in moderation.

 

Ansible for Windows

Ansible is widely known for its usage in Microsoft Windows. It manages and executes major core functions in the Windows environment. These can range from remote management using WinRM to security updates. Yes, Ansible has to be run on Linux. However, Windows administrators may make use of Ansible for managing and automating their systems. This also helps in eliminating the need for knowing how to use a Linux terminal.

With the aid of Red Hat Ansible Automation Platform’s Window, you can carry out a hefty number of tasks. Here are some of them.

  • You can install and uninstall MSIs as you wish
  • You will be able to start, manage, and stop Windows services as you go
  • You can easily manage Windows packages
  • Fetching files from any remote site becomes easier
  • You will be able to enable and disable Windows features swiftly
  • Creating and managing local users and groups is made easy
  • Manage and install Windows updates as you go now
  • PowerShell scripts can easily be now pushed and executed

 

It is important to note that various rules and syntax that are applicable for Linux or Unix hosts are also applicable to Windows when using Ansible for managing Windows. That said, there are still a few differences. These lie in certain components such as OS-specific tasks and path separators.

When we talk about getting started with Ansible for Windows in your testing or development environment, the PowerShell script ConfigureRemotingForAnsible will be really helpful. This script configured WinRM on all supported Windows client or server target.

 

Conclusion

Ansible is a field that is humongous. You can do a lot of things with Ansible. Companies today know this and thus use this automation engine to their benefit thoroughly.

If you want to make a career for yourself in this field, then you need to get started with the right training and certification course. For this, you need to first pick an institute you can rely upon. Grras Solutions is a leading institute in the field of IT training and certification.

For the last 14 years, Grras Solutions has ensured to help students in every which way possible. From quality training by experts to helping them expand their skills via working on live projects, Grras Solutions has brought it all on the table. If you are looking to become an expert in this brilliant field, then there can be no better way to begin than with the best.

Start your Ansible journey by getting trained by industry experts. This is your opportunity to find yourself in some of the best learning environments. Learn not just by listening but also working on live projects. This practical knowledge will also help you land the job of your dreams.

Additionally, Grras Solutions also give you 100% job assistance. Thus, you will not find yourself without any support or sense of direction. Experts of Grras will always be here to help you. Become a lifetime member of this institute by enrolling today. If you ever feel like you want a quick revision in your future, Grras will be more than happy to help you out. No added fee, no questions asked!

0 Comment(s)

Leave your comment

1 Year Diploma Program

Absolutely FREE & 100% JOB GUARANTEE

Get training on Linux, Ansible, Devops ,Python , Networking , AWS and Openstack Cloud by Certified Trainers at GRRAS. You would be able to get the best training along with the interview preparation in this course module .

Get Started