Faster delivery can result in improved support and for stakeholder satisfaction, faster delivery and improved productivity will be the most important thing while automating any service and it is very much satisfied here.
We can do below operations in Service Now using ansible
Updating incidents, problems, and change requests
Updating the Service Now configuration management database (CMDB)
Using the CMDB as an inventory source
In this post will demonstrate, how to manage incidents.
First, we need install the collation to handle any service and here we need to install.
servicenow.itsm collection to manage service servicenow through ansible.
Install Service Now collection using below command:
Will see How Configuration management puppet works in this post.
Let us take a example to create user in complex environment with different Linux distribution. To create a user we have small different in command when we go with different distribution like Red Hat, Ubuntu, CentOS,etc.
We have two method to create user without puppet help.
We can directly login to the servers and will create user when the number of server is less. But, in when the server number hits more 100, its very difficult to create user manually in all user.
We can create script to manage user in all servers. But, for that we should have knowledge about scripting and command different and flags(-u, -U) for each distribution. Once the script created, we need a common server which has access to all the other Linux servers.
But, using puppet we can do any type of user/group management, Package installation, service start/stop/restart, etc. By using puppet built-in resources to achieve the same operation on different distribution without worry about the underlying Operating System and commands.
By using simple code will do the necessary configuration management like user/group management, Package installation, service start/stop/restart,etc.
Example: To create user will write below code to perform the task over all the Linux machines.
Same like above if you want to delete a user/ install package, etc. Solution is wring simple, robust, idempotent, extendable puppet code to the necessary configuration over remote servers.
same like that will see the code to install ntp package, which is used for network time and starting service.
Like this will manage environment using puppet code. In other work managing environment using code will call as Iac(Infrastructure-as-Code). This code will be applied over all the client machines to do the operation and will reduce the manual effort and time.
And its very essay to change the code for any modification on configuration management over all client machines.
Idempotency: Puppet codes are idempotent by nature. Which means the results of the code remains same irrespective of the number of time we perform puppet run on nodes.puppet always ensure to keep the resources in desired state. For example in user creation, it will check whether the user is already exist. If the user already exist, will not perform the user creation and report us that the user already exist. Basically these checks are already in place of the puppet resources. And if you have lines of codes to perform a action on remote machines, in such case, if any of your action already exist in any server, puppet simply will skip that action and proceed for further configuration.
These all are the good points to why we are using puppet in our environment for configuration management.
Thanks for your support and reading this post. Will post next lecture about puppet in next post.
Ansible is opensource automation tool and will see how to patch linux servers using ansible in this post.
We are going to use RedHat Linux 7.3 Operating System in this practical.
Requirements: 1. Linux Host Installed with Ansible and Yum repository configured with httpd. 2. Linux Host Installed with RHEL 7.4 -> Node machine 3. Since Ansible requires SSH enabled between ansible master and node and don’t have node package, Make sure SSH connection established between Master and node.
4. Run createrepo, “yum clean all” & “yum makecache” commands to update the repository along with new RPM’s.
Now the repository is ready for patching.
Ansible playbook for Linux patching:
Login to Ansible Host and change directory to /etc/ansible
#cd /etc/ansible
2. create playbook called “patching.yml” with below content
# vi patching.yml --- - name: Patch Linux system hosts: Linux_Servers become: true ignore_errors: yes tasks: - name: Copy the Kernel Patch Repo File copy: src: /etc/yum.repos.d/yum.repo dest: /etc/yum.repos.d/ - name: Apply patches yum: name: kernel state: latest
3. Edit /etc/ansible/hosts file and provide Linux hosts which needs to be patched and mention group as “Linux_Servers” for those hosts. Host group name has been mentioned in playbook in “hosts: Linux_Servers” portion.
Will see About puppet in this post. Puppet is a open source configuration management tool. Which will help us to reduce our working time by automating most of the day-to-day and other tasks in IT environment.
puppet is declarative one(Puppet domain specific language). Puppet take care of all our regular repetitive task along with application deployment. configuration changes,etc. Puppet written in Ruby. Puppet is scale-label, which can be used any physical/virtual environments. Codes written in puppet are idempotent by naturally. It easily create/update and maintain the OS configuration files using its own declarative methods.
We can do below things using puppet on our OS without any human intervention.
* Installing application on various machines * Managing Firewall ports * Modifying configuration files * Managing services, etc.
We have N number of Resources and Classes to build easily a complex environment over VMWare, Any Cloud environments.
How Puppet Works?
We have Master and agent concept in Puppet environment.
Master should be Installed and configured on Linux machines only and there is no support for Windows machine. But Agent can be Linux or Windows machines.
We have two deployment models
Master-Agent deployment : Master and agent machines different machines. Master will manage the agent machines. Its used for Production environment
Standalone deployment: Master and agent both packages are installed on one server and its used for Dev/Test Environment.
Puppet Master are Linux based machine where we need to install and configure “puppetserver” package and this will be responsible to create and maintain puppet codes to manage agent machines.
Agent machines are different servers in our environment which we would like to manage using puppet.
“Puppet-agent” package should be installed on agent machines
Agent machines will check with Master every “1800 Seconds(30 Mins)” to know if anything to be updated on agent machine.
If anything needs to be updated, Agent will pull from Master machine through puppet codes and this will be called us “pull mechanism” and will do required updates which is mentioned in puppet codes.
And we have “Push and Pull” based deployment.
In Push based, master will push the configuration updates to their agent machines
In Pull based model, Agents will establish connection with master and will pull the updates from master in periodic interval.
Workflow:
Administrator Login on Puppet Master to create/ Update puppet codes and this machine is responsible for puppet code management and contains different configurations in environment.
We have multiple agents in environment and puppet-agent package installed on agent machines.
Communication between master and agent will be established through secured certificates.
Puppet master will allow agent machines through port 8140
We make sure port 8140 enabled on firewall
Communication between master and agent has three steps
Once communication established, Agents send data to Master and the data includes, Host name, IP Address and MAC Address. These are called as facts.
Master uses this facts and compile a list with configuration which needs to be applied on agent and this will be called as catalog.
Catalog contains data such as packages to be installed/services, etc. which needs to be updated on agent machines based on puppet codes which wrote.
Agent uses the catalog to apply required changes on the nodes
Once agent received catalog, it will do required changes and nodes will report to master that will say the configuration has been applied ans successfully completed.
Puppet provides compatibility to get these reports using third party tools.
Docker Inc still didnt replease Docker for RHEL8/ CentOS 8. So, we can use alternate one which is used for RHEL7/ CentOS7
# curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2424 100 2424 0 0 22238 0 --:--:-- --:--:-- --:--:-- 22238
Docker community edition requires container.io => 1.2.2.3. But, its not available for RHEL/ CentOS 8. So, we need to skip and proceed the the docker installation in our own RISK.
# yum install docker-ce Docker CE Stable - x86_64 16 kB/s | 21 kB 00:01 Error: Problem: package docker-ce-3:19.03.5-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
cannot install the best candidate for the job package containerd.io-1.2.10-3.2.el7.x86_64 is excluded package containerd.io-1.2.2-3.3.el7.x86_64 is excluded package containerd.io-1.2.2-3.el7.x86_64 is excluded package containerd.io-1.2.4-3.1.el7.x86_64 is excluded package containerd.io-1.2.5-3.1.el7.x86_64 is excluded package containerd.io-1.2.6-3.3.el7.x86_64 is excluded (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
Installing docker by skipping unavailable packages
Now Docker Version “3:18.09.1-3.el7.x86_64” has been installed.S
Start and enable the Docker service by using below command
# systemctl start docker
# systemctl enable docker Created symlink /etc/systemd/system/multi-user.target.wants/docker.service â /usr/lib/systemd/system/docker.service.
Check the docker service status
# systemctl status docker â docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2020-01-17 05:37:17 UTC; 2min 4s ago Docs: https://docs.docker.com Main PID: 15635 (dockerd) Tasks: 18 Memory: 53.5M CGroup: /system.slice/docker.service ââ15635 /usr/bin/dockerd -H fd:// ââ15649 containerd --config /var/run/docker/containerd/containerd.toml --log-level info Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.341886251Z" level=info msg="Graph migration to content-addressabil> Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.342289173Z" level=warning msg="Your kernel does not support cgroup> Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.342309354Z" level=warning msg="Your kernel does not support cgroup> Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.342708097Z" level=info msg="Loading containers: start." Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.556082824Z" level=info msg="Default bridge (docker0) is assigned w> Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.654816733Z" level=info msg="Loading containers: done." Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.681089736Z" level=info msg="Docker daemon" commit=4c52b90 graphdri> Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.681241065Z" level=info msg="Daemon has completed initialization" Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal dockerd[15635]: time="2020-01-17T05:37:17.717122644Z" level=info msg="API listen on /var/run/docker.sock" Jan 17 05:37:17 ip-172-31-44-32.us-east-2.compute.internal systemd[1]: Started Docker Application Container Engine.
Now check the Docker installation by running a container using anyone the base image
# docker run -it hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f Status: Downloaded newer image for hello-world:latest
Hello from Docker! This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps: The Docker client contacted the Docker daemon. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/
For more examples and ideas, visit: https://docs.docker.com/get-started/
Allowing non root users:
Check whether group called “Docker” availavle or not
# cat /etc/group | grep docker
docker:x:989:
Since group already exists, Now create a new user
# useradd abu
Check created users details like default UID, GID/ Groups added
# id abu uid=1001(abu) gid=1001(abu) groups=1001(abu)
Now add “abu” user to “Docker” group as another group.
# usermod -aG docker abu
# id abu uid=1001(abu) gid=1001(abu) groups=1001(abu),989(docker)
Now we can use this user to run docker instead if using root user.
Before installing the Docker Engine on your host, you need to setup the repository first. So, will see How to setup Docker Repository in this post. After that, you can Install/Update the Docker from the repository.
# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2020-01-02 02:14:11 EST; 8s ago Docs: https://docs.docker.com Main PID: 60692 (dockerd) Memory: 37.6M CGroup: /system.slice/docker.service └─60692 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Jan 02 02:14:10 localhost dockerd[60692]: time="2020-01-02T02:14:10.667134175-05:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:/…odule=grpc Jan 02 02:14:10 localhost dockerd[60692]: time="2020-01-02T02:14:10.667153441-05:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc Jan 02 02:14:10 localhost dockerd[60692]: time="2020-01-02T02:14:10.695465002-05:00" level=info msg="Loading containers: start." Jan 02 02:14:10 localhost dockerd[60692]: time="2020-01-02T02:14:10.952900918-05:00" level=info msg="Default bridge (docker0) is assigned with an IP ad…P address" Jan 02 02:14:11 localhost dockerd[60692]: time="2020-01-02T02:14:11.018716067-05:00" level=info msg="Loading containers: done." Jan 02 02:14:11 localhost dockerd[60692]: time="2020-01-02T02:14:11.040693143-05:00" level=warning msg="Not using native diff for overlay2, this may ca…r=overlay2 Jan 02 02:14:11 localhost dockerd[60692]: time="2020-01-02T02:14:11.041056334-05:00" level=info msg="Docker daemon" commit=633a0ea graphdriver(s)=overl…on=19.03.5 Jan 02 02:14:11 localhost dockerd[60692]: time="2020-01-02T02:14:11.041178502-05:00" level=info msg="Daemon has completed initialization" Jan 02 02:14:11 localhost dockerd[60692]: time="2020-01-02T02:14:11.072808771-05:00" level=info msg="API listen on /var/run/docker.sock" Jan 02 02:14:11 localhost systemd[1]: Started Docker Application Container Engine. Hint: Some lines were ellipsized, use -l to show in full.
Now verify the Docker using below command
# docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:4fe721ccc2e8dc7362278a29dc660d833570ec2682f4e4194f4ee23e415e1064 Status: Downloaded newer image for hello-world:latest
Hello from Docker! This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/
For more examples and ideas, visit: https://docs.docker.com/get-started/
Thanks for reading this post and going forward will talk about Docker Engine more…
We are going to see how to install Ansible on RHEL7/ CentOS7 in this post.
Control node needs to install Python 2.6 or latest version and windows doesn’t support for control node.
Since the ansible agentless tool, on Managed hosts no need to install any specific agent/client. And need to install python 2.4 or latest version on managed hosts.
Finally, we installed ansible over our machine which we are going to take it as a control node.
Hereafter if we want to deploy or manage any remote hosts(Managed Host) from the control node, SSH authentication is mandatory. So, We should copy and paste the SSH keys to the remote hosts to make the communication available between the control and managed node.
we are going to see the Architecture of Ansible in this post.
Communication:
Communication established between control node(Server) and Managed hosts(Client machines) using SSH Protocol.
A normal user will be sufficient for communication between Control and Managed hosts.
A normal user can able to perform a few tasks but for other tasks, we need administrators user or other users who have sudo access to perfom that tasks.
complete Architecture detail of Ansible:
This will explain how the ansible working and what are all the things contains as architecture.
As we can see the above diagram ansible automation engine will interact directly with the person who writes playbooks to do tasks.
It also interacts with the cloud(public/private) directly. Basically its CMDB(Configuration Management Data Base).
Also, it contains the below components:
Inventory
Modules
API
Plugins
Inventory:
Inventory will contain the List of Host or IP Address of Host/ Wildcards where we are going to do automation tasks using ansible.
We can specify the different inventory path using -i option.
Modules:
Ansible has more 1000 readymade playbooks in it and we should use those modules in paybooks to do automation tasks. Modules will be copied from Control node to managed hosts while executing the tasks and it will run the program based on playbook and Module then will give back us the output.
Also, the user can create custom playbooks based on their needs.
We should mention the modules in playbooks and modules will be directly executed in remote hosts through playbooks and will get the output.
API:
Ansible uses API as transport for Cloud services.
Plugins:
Plugins will enhance the features ansible.
Plugins will allow executing the task on build stat. Its a piece of code.
Using ansible we can automate the tasks on different types of network.
We are going to see Introduction of Ansible automation tool in this post. By reading the future post you can learn full ansible automation and it’s purely based on RedHat Linux.
Ansible is written by Micheal DeHaan
What is Ansible?
It’s a simple IT automation and powerful configuration management tool which is written in python.
It’s an open source configuration management tool.
We can standardize our environment configuration from one server to all other remote servers using ansible by creating the playbooks to complete that task.
Mainly it’s agentless automation tool. Work is pushed to the remote host when the ansible executed.
What we can do:
Configuration of Servers
Application Deployments
Continuous testing of existing application
Provisioning
Orchestration
Automating our administration tasks
What we cannot do:
We cannot install the initial minimum installation of the system.
We cannot monitor the servers
It will not track what changes are made over the files on the system.
How the Ansible work:
Ansible Syntax (or) ansible adhoc command:
Ex:
#Ansible -m command -a "uptime" Test
Ansible:- Keyword
m:- Module
command:- Module Name
uptime:- OSCommand
Test:- Target server Group
Ansible Features:
Easy to learn
Written in python
Agentless
YAML based playbooks
Ansible Galaxy
Ansible Modules:
It’s having 1375 modules. For each and every operation we need to use modules to run the commands.
So we should understand the modules to do automation.