Ansible

Ansible AD HOC Command Examples – Ansible Cheat Sheet

Ansible AD HOC Command Examples - Ansible Cheat Sheet Excerpt Ansible ad hoc commands are one-liners designed to achieve a very specific task they are like quick snippets and your compact swiss army knife when you want to do a quick task across multiple machines. Simply put, Ansible ad hoc commands are single-line Linux shell commands, and a playbook is like a shell script, a collection of multiple commands with logic. Ansible special commands are single lines designed to accomplish a very specific task. They are like quick extractors and your compact Swiss army knife when you want to complete a task quickly on multiple machines. Simply put, Ansible ad hoc commands are single-line Linux shell commands, and a playbook is like a shell script, a collection of multiple commands with logic. Ansible special commands are useful when you want to perform a quick task. We’ve collected over 20 examples that will help you get started with Ansible AD HOC commands. This is your Ansible AD HOC command cheat sheet or Ansible cheat sheet. Prerequisites Must install Ansible (only on the control machine, remember there is no agent) Some remote virtual machines to test, you can use vagrant to build them.

Continue reading

Ansible apt module Examples - install with apt

Excerpt Ansible APT Package manager is an Ubuntu equivalent for RedHat yum package manager. Just like all other ansible modules apt ansible module is built after one specific unix command of Debian apt-get It is always recommended to choose the modules rather using the raw unix commands over the shell module as it would bring more standard and fault tolerance to your Ansible Playbook The Ansible APT package manager is the Ubuntu equivalent of the RedHat yum package manager. Just like all other Ansible ‘apt’ modules, the Ansible module is built after the Debian-specific Unix ‘apt-get’ command You should choose modules instead of using raw Unix commands instead of shell modules as this will bring more standards and fault tolerance to your Ansible Playbook. So how to use apt ansible module in playbook or in special way. GOOD!. This article will cover the ansible apt module in detail with various examples. Introduction to ansible apt module Ansible apt module manages apt packages in Debian or Ubuntu systems. In typical Ubuntu machine, in order to install a package, you would execute the following command apt install nginx Same way here in ansible, the following playbook/play would do that for you

Continue reading

Ansible Command Module Examples

Excerpt Ansible Command module is used to execute commands on a remote node. The Command module is mainly used to execute simple Linux commands on a remote node/server that is part of a server group or a standalone server mentioned in the server group. If you want to run some simple shell commands on a remote server, you can use Ansible Command Module Examples The Ansible Command module is used to execute commands on the remote node. The Command module is mainly used to execute simple Linux commands on a remote node/server that is part of a server group or a standalone server mentioned in the server group. If you want to run some simple shell commands on a remote server, you can use this Ansible command module . But when there are no overly complicated shell commands or two commands concatenated with PIPE. you cannot use this command module and you must choose the shell module instead of this one. Not just a pipe, if you use one of these characters like | > < in your command you should consider using the shell module Where to use Ansible SHELL and Where to use Ansible COMMAND? ls -lrt /etc/httpd/conf is simple and can be executed with Ansible command module

Continue reading

Ansible Dry Run – How to Run Playbook in Ansible Check mode

Excerpt Introduction Ansible Dry Run or Ansible Check mode feature is to check your playbook before execution like Ansible’s –syntax-check feature. With Ansible Dry Run feature you can execute the playbook without having to actually make changes on the server. With Ansible Dry Run you can see if the host is getting changed or not. Introduction Ansible Dry Run or Ansible Check mode feature is to check your playbook before execution like Ansible’s --syntax-check feature. With Ansible Dry Run feature you can execute the playbook without having to actually make changes on the server. With Ansible Dry Run you can see if the host is getting changed or not. Here is a sample playbook is written to install and start the Apache HTTPD web server. --- - name: Playbook hosts: webservers become: yes become_user: root tasks: - name: ensure apache is at the latest version yum: name: httpd state: latest - name: ensure apache is running service: name: httpd state: started Our objective is to install Apache web server and start it but if we want to see if it would affect/change the host or throw error . We can Dry Run this Playbook with no further ado, Let me tell you how to Run the Ansible Playbook in Check mode or dry run mode ASCII Video

Continue reading

Ansible Find Example 0s – How to use Ansible Find

Excerpt The Ansible search module works similarly to the Find Linux command and allows searching files and folders based on various search criteria like file age, access date, modification date, expression search pattern regular, etc. As stated earlier, this is a more feasible way to run the Linux find command with an inbuilt standard, this module is designed. As stated earlier, this is a more efficient way to run the Linux find command with an existing standard. This module is intended for use on Linux servers only. For Windows, you should use the win_find module instead. Because this will also be the command to replace Linux Find. I will list all 0 examples equivalent to Linux Find. Example 01: Find all the log files older than 30 days with Ansible Find In this section, we are going to see how ansible find is going to help us find the more than 30 days old files. The Linux find Command Here is the command that you would ideally execute in the Linux OS find /var/log -name "*.log" -type f -mtime +30 The Ansible Find AdHoc Command The same Linux command can be rewritten as ansible ad hoc command as follows

Continue reading

Ansible Reboot system and wait_for reboot to complete - Middleware Inventory

Ansible Reboot system and wait_for reboot to complete Excerpt The Objective The purpose of this post is to explain with an example of how ansible initiate the reboot and wait for the reboot to complete There are cases where we want our remote nodes to be rebooted or restarted. For example, Take the Patching as an example. As part of quarterly patching, we upgrade the installed software and packages and do The Objective The purpose of this article is to explain with an example how Ansible initiates a reboot and waits for the reboot to complete. There are cases where we want our remote nodes to be rebooted or restarted. For example, let’s take patching as an example. As part of our quarterly patches, we upgrade installed software and packages and perform many other tasks as well as a final reboot for the changes to take effect. When we restart the server (box). Your ansible read may fail due to error “Shared connection closed” But this can be avoided and you can reboot the box and wait for the server to reboot and then run validation or tests after reboot. How to reboot and wait for it to complete with ansible There are many methods to accomplish this

Continue reading