<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ansible Info's]]></title><description><![CDATA[Ansible Info's]]></description><link>https://ansible-infos.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 15:24:38 GMT</lastBuildDate><atom:link href="https://ansible-infos.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Ansible Highlights]]></title><description><![CDATA[Ansible

ansible is configuration management tool came after Puppet , Salt Stack, Chef and befor terraform
It is build on principle of simplicity
configuration management -> its going to compare the state , if changed it apply (Indepodent)
Use-cases
...]]></description><link>https://ansible-infos.hashnode.dev/ansible-highlights</link><guid isPermaLink="true">https://ansible-infos.hashnode.dev/ansible-highlights</guid><dc:creator><![CDATA[Manoj M]]></dc:creator><pubDate>Wed, 30 Jul 2025 22:37:25 GMT</pubDate><content:encoded><![CDATA[<h1 id="heading-ansible">Ansible</h1>
<ul>
<li>ansible is configuration management tool came after <strong>Puppet , Salt Stack, Chef</strong> and befor <strong>terraform</strong></li>
<li>It is build on principle of simplicity</li>
<li>configuration management -&gt; its going to compare the state , if changed it apply (Indepodent)</li>
<li>Use-cases<ul>
<li>Any System autamation (<strong>Automation</strong>)</li>
<li>Production server changes (<strong>Change mgmt</strong>)</li>
<li>Setup Servers from scratch/Cloud provisioning (<strong>Provisioning</strong>)</li>
<li>Large scale automation framework (<strong>Orchestration</strong>)</li>
</ul>
</li>
<li>No agents -&gt; target machins/Services are accessed by SSH. winrm &amp; API</li>
<li>No databases -&gt; YAML, INI &amp; text</li>
<li>No complex setup -&gt; just a python lib</li>
<li>No Residual Software -&gt; push python package , execute, return output</li>
<li>API based calls</li>
</ul>
<h3 id="heading-yaml">YAML</h3>
<ul>
<li>playbooks are written in YAML</li>
</ul>
<h3 id="heading-ansible-connection">Ansible Connection</h3>
<ul>
<li>Linux-server -&gt; ssh</li>
<li>Windows -&gt; winrm</li>
<li>cloud -&gt; API's</li>
<li>can also use network routers or some thing</li>
<li>the conclusion is that ansible doesn't need any agent or servers to connct to machines thats why we dont call ansible as ansible servers</li>
</ul>
<h3 id="heading-ansible-architecture-not-official">Ansible Architecture (Not Official)</h3>
<ul>
<li>Inventry file -&gt; have target machin info's, how to connect to host like mentioning username, password etc</li>
<li>Playbooks -&gt;  we write playbooks like what we need to execute</li>
<li>Ansible config - configuration details</li>
<li>Modules -&gt; ansible have so many modules to create databases, taking snapshots etc. it will used in above</li>
<li>After all the things done it will be created to python packege and sends to target OS. If the target is not OS like it is Cloud then it will executed locally</li>
</ul>
<h3 id="heading-connecting-target-machine-from-control-machine">Connecting target machine from control machine</h3>
<ul>
<li>So connect to target machine using ssh. So , write a inventory file and execute using <code>ansible hostname -m &lt;module-name&gt; -i &lt;inveentory-file&gt;</code></li>
<li>you can use regex in mentioning hostname like <em>, web-</em> etc.</li>
<li>In inventry file if you mention <code>*.pem</code> file for authentication make sute it have permission <strong>400</strong></li>
<li>Actully it will ask again the same question like <strong>Are you sure do you want to connect to that machine</strong> So to make complete automation we can disable it in ansible configuration file.<ul>
<li>Initially there is default file <code>ansible.cfg</code> in folder <code>/etc/ansible</code> but to create actual file we need to create backup of that file and <code>cat ansible.cfg</code> you will get cmd to create actual config file.</li>
<li><code>vim ansible.cfg</code> (make sure you are in folder <strong>/etc/ansible</strong>) then uncomment the <strong>host_key_checking</strong> and make it <strong>False</strong></li>
</ul>
</li>
</ul>
<h3 id="heading-group">Group</h3>
<ul>
<li>If you have may hoste make the group and run</li>
</ul>
<h3 id="heading-community-mysql-requirement">Community My_sql requirement</h3>
<ul>
<li>please follow procedures present in doc <a target="_blank" href="https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_db_module.html#ansible-collections-community-mysql-mysql-db-module">ansible my-sql community doc</a></li>
</ul>
<h3 id="heading-cmds-example">cmd's example</h3>
<ul>
<li><code>ansible web01 -m "ansible.builtin.yum" -a "name=httpd state=present" -i inventory  --become</code> -&gt; to run as root (--become)</li>
<li><code>ansible webservers -m "ansible.builtin.service" -a "name=httpd state=started enabled=yes" -i inventory  --become</code> -&gt; start and enable http</li>
<li><code>ansible webservers -m "ansible.builtin.copy" -a "src=index.html dest=/var/www/html/index.html" -i inventory  --become</code> copy index.html file from control machine</li>
<li><code>ansible webservers -m yum -a "name=httpd state=absent" -i inventory --become</code> cmd to remove packages like httpd</li>
<li>playbooks will be in yaml (i.e .yaml file) , to run run playbook cmd is <code>ansible-playbook -i inventory web-db.yaml(playbook)</code> and <code>ansible-playbook -i inventory web-db.yaml -v</code> for debugging or <code>ansible-playbook -i inventory web-db.yaml -vv</code> and <code>ansible-playbook -i inventory web-db.yaml -vvv</code> and <code>ansible-playbook -i inventory web-db.yaml -vvvv</code> for more details in cmds</li>
<li><code>ansible-playbook -i inventory web-db.yaml --syntax-check</code> for syntax check</li>
<li><code>ansible-playbook -i inventory web-db.yaml -C</code> for dry-run which means it run but not the actually execution. Some times it is going to give error but run in actual execution (ex: when we write update_cache is true)</li>
<li>link for module realted doc <a target="_blank" href="https://docs.ansible.com/ansible/latest/collections/index_module.html">List of modules</a></li>
<li>Some extra dependencies (mostly pythons) needed for some modules id the requirements not satisfiled we will get the error</li>
</ul>
<h3 id="heading-ansible-configuration">ansible configuration</h3>
<ul>
<li>Always have <code>ansible.cfg</code> file in your repository -&gt; best practices</li>
<li>Levels (priority in order)<ol>
<li>ANSIBLE_CONFIG (env var if set)</li>
<li>ansible.cfg (in current dir) -&gt; best for SCM and working in teams</li>
<li>~/.ansible.cnf (in the home dir)</li>
<li>/etc/ansible/ansible.cfg (global)</li>
</ol>
</li>
</ul>
<h3 id="heading-variables">Variables</h3>
<ul>
<li>where are we can define vars<ul>
<li>cmd line (rarely used)</li>
<li>Playbooks</li>
<li>Inventory file (host_vars or group_vars)</li>
<li>Roles</li>
</ul>
</li>
<li><strong>Fact Variables</strong> : setup modules -&gt;  don't need to run setup module when ansible executed setup mudules run and fact variables are generated (ex: ansible_os_family). Until we explicitly use it , it won't used from setup module</li>
<li><strong>Storing output</strong>: register module -&gt; when module exec return in jeson format from that we can store that and use it</li>
</ul>
<h3 id="heading-template-module">Template module</h3>
<ul>
<li>Copy module just copy the file but the template module is based on <strong>Jinja</strong> templating like it will read the template file and paste it in target location. Like we can put ENV var in template file so that template mpdule put the env var and then it will copy the file</li>
</ul>
<h3 id="heading-configuring-ntp-file-chrony-or-ntp-package">Configuring NTP file (Chrony or ntp package)</h3>
<ul>
<li>NTP -&gt; network time protocol use to synchronize the time with multiple devices in network</li>
<li>CentOs/AMAZON linux<ul>
<li>config file present in <code>/etc/chrony.conf</code></li>
</ul>
</li>
<li>Ubuntu<ul>
<li>config file present in <code>/etc/ntpsec/ntp.conf</code></li>
</ul>
</li>
</ul>
<h3 id="heading-handlers">Handlers</h3>
<ul>
<li>So when we have service and it is active and changed then we need to restart the service we can write a code for that but even the service get restart when it is not chaanged. So handel this type of senario we use Handlers</li>
<li>To do this<ol>
<li>Put the tasks in handlers section</li>
<li>To trigger handler we need to notify it</li>
<li>Provide <strong>notify</strong> key in the task where the hander need to be notify with value as <strong>Exact name of hander task</strong></li>
</ol>
</li>
</ul>
<h3 id="heading-ansible-roles">Ansible Roles</h3>
<ul>
<li>Simplifies or seggregates all content from complrx playbooks</li>
<li>Oraganization level and specifically use for reusability</li>
<li>converting already ansible dir to roles are very easy<ul>
<li>create roles dir `mkdir roles'</li>
<li>cd to that folder</li>
<li>then run the cmd <code>ansible-galaxy init post-install</code></li>
<li>this will create a roles dir structure then copy all the templates, vars , files, tasks and handlers to respective dirs and main folder</li>
<li>then remove the folder and task and handler content in play-book then it will look simple</li>
<li>so add <strong>roles</strong> attr and add role name there</li>
<li>then in roles tasks folder main.yml file remove <strong>/templete</strong> dir structure in or any other structure mentioned in playbook because roles are intellegent enough to find the things and also make sure the template files are end with <strong>.j2</strong> suffix</li>
</ul>
</li>
</ul>
<h3 id="heading-ansible-on-aws">Ansible on AWS</h3>
<ul>
<li>Create access credentials in aws and add it in control machine using<ul>
<li><code>export AWS_ACCESS_KEY_ID=</code></li>
<li><code>export AWS_SECRET_ACCESS_KEY=</code></li>
</ul>
</li>
<li>The above method is like it will erase when we restart the system so to make it completely available make sure you mention the same in <code>.bashrc</code> file. This will execute when the system booted. At last do <code>source .bashrc</code></li>
</ul>
]]></content:encoded></item></channel></rss>