In previous post we have understood the usage and basics of Ansible. Also we have have installed Ansible on RHEL8 and setup our Lab environment so that we can practice. Now this is time to move ahead and learn more about Ansible and see how we can use an intelligent configuration management automation tool in our environment. There are two types of automation approaches we can adopt in our environment for configuration management: -
1. Traditional Automation: - Automation using scripts which can be written in any scripting language (Shell, Perl, Python etc.). In this approach as per requirement we write a script and whenever we run this script it do the needful. This kind of automation works fine until there is any change in environment. But as we know this is not possible, our environment keep on changes and slight change may fail our automation completely. How?
Example: - Configure httpd on RHEL6, below are the simple commands we use to configure httpd in RHEL6. Which we can put in syntax of any scripting language and get our work done. Steps: - Install httpd RPM > Configure httpd config > start httpd service.
This script will work on all the RHEL6 server and keep on configuring web server but let's suppose there was some requirement and management has decided to upgrade environment on latest Red Hat OS which is RHEL8. Now the problem starts, as we know that to install a package we have dnf command, to start service we have systemctl command in RHEL8. I also know that as of now service and yum commands are there in RHEL8 we can use them but later or sooner these will be removed only dnf and systemctl would be available so considering that service and yum commands are not available. In this scenario the script will fail, it won't work. So we have to ask our developer to update the script according and also it may be that developer don't have experience of RHEL8, so first of all he will learn then he will write the script or he need help of someone who has experience on RHEL8. So finally this kind of issues are very common and no one want to fall into these. To fix this kind of issues we need some intelligent automation approach which works across all the environment. Next approach is made for that only.
2. Configuration management tools based Automation: - Automation using configuration management tools(Ansible, Puppet, Chef). These are intelligent automation tools. Why I am saying these are intelligent because in these tools we don't have to tell how you have to perform the task? We only have to tell what it has to do?, Here we will discuss about Ansible. If we continue our previous example of configuration of web server, we just have to tell to Ansible that configure httpd in my environment we never tell how you have to configure httpd. As I mentioned Ansible is an intelligent tool so internally it check on which OS, which version it is and then simply configure it. You don't need to bother about it. This is very simple explanation of why we need configuration management tools like Ansible, Chef and Puppet?
How to start using Ansible: - There are two way of using Ansible - 1. Ad-hoc commands and 2. Playbooks. Ad-hoc commands are easy, quick and good for single task on one or more managed hosts but these are undocumented so can't used again(not reusable). We will start with ad-hoc commands and later on move on playbooks and best practice is also playbooks only. Playbook contain one or more play(task) on one or managed hosts. In simple words playbook is a YAML file in which we write tasks(play) which will be performed on controller nodes. Lets perform some ad-hoc commands and then perform the same using playbook. Make a note I'll perform each step (controller node)ansible.example.comand then verify the same on managed node.
[root@ansible ~]# ansible all -m service -a "name=httpd state=started"
Nice article, keep sharing the knowledge
ReplyDelete