Ansible is an agentless Orchestrator and an Automation tool that makes Linux/Windows applications and systems easier to provision, deploy, and do configuration management tasks. In this blog, we will focus on installing Ansible on our Redhat 9 and this install will form the base for our Aria Automation stack we will build on later during our journey.
During the tour, we will install Ansible Tower on our RHEL 9 System which takes Ansible to the next level by introducing a web-based infrastructure automation platform for centrally managing and configuring all our Linux/Microsoft Windows Servers via the UI. Ansbile tower is free for usage for up to 10 nodes so we can deploy with just a trial subscription from Redhat.
Note: With Redhat 9 and above, the Ansible Core package is by default included in the AppStream repository so there is no longer a requirement to add an EPEL repository that was very commonly used with previous RHEL 8 and below versions.
Components of Ansible Engine
- Control Node – Also known as the brain of the system that has Ansible installed.
- Managed Node – These are the clients in simple terms.
- Host Inventory – List of all hosts that can be managed with Ansible eg: Webservers
- PlayBooks – are a set of group-related tasks that are to be executed on a managed node eg; Prod Dev, etc
- Modules – ready-to-use codes that help in package installation, file manipulation and service management that are run when a playbook is run. Modules are stored in the /lib/ansible/modules.
Ansible Tower (AWX) Deployment Prerequisites
With Redhat 9 and above, the Ansible Core package is by default included in the AppStream repository so there is no longer a requirement to add an EPEL repository that was very commonly used with previous RHEL 8 and below versions.
Installing Ansible on Red Hat 9
Refresh the yum cache by running the following command;
1 2 3 4 5 6 |
<span class="line"><span style="color: #EEFFFF">[root@aap </span><span style="color: #89DDFF">~</span><span style="color: #EEFFFF">]# dnf makecache</span></span> <span class="line"><span style="color: #EEFFFF">Updating Subscription Management repositories</span><span style="color: #89DDFF">.</span></span> <span class="line"><span style="color: #EEFFFF">Red Hat Enterprise Linux </span><span style="color: #F78C6C">9</span><span style="color: #EEFFFF"> for x86_64 </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF"> </span><span style="color: #82AAFF">BaseOS</span><span style="color: #EEFFFF"> (RPMs) </span><span style="color: #F78C6C">2.7</span><span style="color: #EEFFFF"> MB</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">s </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">17</span><span style="color: #EEFFFF"> MB </span><span style="color: #F78C6C">00</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">06</span></span> <span class="line"><span style="color: #EEFFFF">Red Hat Enterprise Linux </span><span style="color: #F78C6C">9</span><span style="color: #EEFFFF"> for x86_64 </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF"> </span><span style="color: #82AAFF">AppStream</span><span style="color: #EEFFFF"> (RPMs) </span><span style="color: #F78C6C">3.5</span><span style="color: #EEFFFF"> MB</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">s </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">29</span><span style="color: #EEFFFF"> MB </span><span style="color: #F78C6C">00</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">08</span></span> <span class="line"><span style="color: #EEFFFF">Metadata cache created</span><span style="color: #89DDFF">.</span></span> <span class="line"></span> |
Update all software packages on the system using dnf update –y
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<span class="line"><span style="color: #EEFFFF">[root@aap </span><span style="color: #89DDFF">~</span><span style="color: #EEFFFF">]# dnf update </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">y</span></span> <span class="line"><span style="color: #EEFFFF">Updating Subscription Management repositories</span><span style="color: #89DDFF">.</span></span> <span class="line"><span style="color: #EEFFFF">Last metadata expiration </span><span style="color: #FFCB6B">check</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">0</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">09</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">30</span><span style="color: #EEFFFF"> ago on Sun </span><span style="color: #F78C6C">25</span><span style="color: #EEFFFF"> Feb </span><span style="color: #F78C6C">2024</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">19</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">23</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">57</span><span style="color: #EEFFFF"> GMT</span><span style="color: #89DDFF">.</span></span> <span class="line"><span style="color: #EEFFFF">Dependencies resolved</span><span style="color: #89DDFF">.</span></span> <span class="line"><span style="color: #89DDFF">========================================================================================================================================================================================================</span></span> <span class="line"><span style="color: #EEFFFF"> Package Architecture Version Repository Size</span></span> <span class="line"><span style="color: #89DDFF">========================================================================================================================================================================================================</span></span> <span class="line"><span style="color: #FFCB6B">Installing</span><span style="color: #89DDFF">:</span></span> <span class="line"><span style="color: #EEFFFF"> kernel x86_64 </span><span style="color: #F78C6C">5.14</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">0</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">362.18</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">1</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9_3 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">baseos</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">4.9</span><span style="color: #EEFFFF"> M</span></span> <span class="line"><span style="color: #FFCB6B">Upgrading</span><span style="color: #89DDFF">:</span></span> <span class="line"><span style="color: #EEFFFF"> NetworkManager x86_64 </span><span style="color: #F78C6C">1</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">1.44</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">0</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">4</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9_3 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">baseos</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">2.3</span><span style="color: #EEFFFF"> M</span></span> <span class="line"><span style="color: #EEFFFF"> NetworkManager</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">libnm x86_64 </span><span style="color: #F78C6C">1</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">1.44</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">0</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">4</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9_3 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">baseos</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">1.8</span><span style="color: #EEFFFF"> M</span></span> <span class="line"><span style="color: #EEFFFF"> NetworkManager</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">team x86_64 </span><span style="color: #F78C6C">1</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">1.44</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">0</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">4</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9_3 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">baseos</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">43</span><span style="color: #EEFFFF"> k</span></span> <span class="line"><span style="color: #EEFFFF"> NetworkManager</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">tui x86_64 </span><span style="color: #F78C6C">1</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">1.44</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">0</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">4</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9_3 </span></span> |
To list all repositories on the VM, run dnf repolist . Ansible Core package is by default included in the AppStream repository in RHEL9
1 2 3 4 5 6 |
<span class="line"><span style="color: #EEFFFF">[root@aap </span><span style="color: #89DDFF">~</span><span style="color: #EEFFFF">]# dnf repolist</span></span> <span class="line"><span style="color: #EEFFFF">Updating Subscription Management repositories</span><span style="color: #89DDFF">.</span></span> <span class="line"><span style="color: #EEFFFF">repo id repo name</span></span> <span class="line"><span style="color: #EEFFFF">rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">appstream</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms Red Hat Enterprise Linux </span><span style="color: #F78C6C">9</span><span style="color: #EEFFFF"> for x86_64 </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF"> </span><span style="color: #82AAFF">AppStream</span><span style="color: #EEFFFF"> (RPMs)</span></span> <span class="line"><span style="color: #EEFFFF">rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">baseos</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms Red Hat Enterprise Linux </span><span style="color: #F78C6C">9</span><span style="color: #EEFFFF"> for x86_64 </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF"> </span><span style="color: #82AAFF">BaseOS</span><span style="color: #EEFFFF"> (RPMs)</span></span> <span class="line"></span> |
Install Ansible with dnf command
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<span class="line"><span style="color: #EEFFFF">[root@aap </span><span style="color: #89DDFF">~</span><span style="color: #EEFFFF">]# dnf install </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">y ansible</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">core</span></span> <span class="line"><span style="color: #EEFFFF">Updating Subscription Management repositories</span><span style="color: #89DDFF">.</span></span> <span class="line"><span style="color: #EEFFFF">Last metadata expiration </span><span style="color: #FFCB6B">check</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">0</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">19</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">40</span><span style="color: #EEFFFF"> ago on Sun </span><span style="color: #F78C6C">25</span><span style="color: #EEFFFF"> Feb </span><span style="color: #F78C6C">2024</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">19</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">38</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">59</span><span style="color: #EEFFFF"> GMT</span><span style="color: #89DDFF">.</span></span> <span class="line"><span style="color: #EEFFFF">Dependencies resolved</span><span style="color: #89DDFF">.</span></span> <span class="line"><span style="color: #89DDFF">========================================================================================================================================================================================================</span></span> <span class="line"><span style="color: #EEFFFF"> Package Architecture Version Repository Size</span></span> <span class="line"><span style="color: #89DDFF">========================================================================================================================================================================================================</span></span> <span class="line"><span style="color: #FFCB6B">Installing</span><span style="color: #89DDFF">:</span></span> <span class="line"><span style="color: #EEFFFF"> ansible</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">core x86_64 </span><span style="color: #F78C6C">1</span><span style="color: #EEFFFF">:</span><span style="color: #F78C6C">2.14</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">1</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">appstream</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">2.6</span><span style="color: #EEFFFF"> M</span></span> <span class="line"><span style="color: #EEFFFF">Installing </span><span style="color: #FFCB6B">dependencies</span><span style="color: #89DDFF">:</span></span> <span class="line"><span style="color: #EEFFFF"> python3</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">cffi x86_64 </span><span style="color: #F78C6C">1.14</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">5</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">5</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">baseos</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">257</span><span style="color: #EEFFFF"> k</span></span> <span class="line"><span style="color: #EEFFFF"> python3</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">cryptography x86_64 </span><span style="color: #F78C6C">36.0</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">1</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">4</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">baseos</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">1.2</span><span style="color: #EEFFFF"> M</span></span> <span class="line"><span style="color: #EEFFFF"> python3</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">packaging noarch </span><span style="color: #F78C6C">20.9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">5</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">appstream</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">81</span><span style="color: #EEFFFF"> k</span></span> <span class="line"><span style="color: #EEFFFF"> python3</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">ply noarch </span><span style="color: #F78C6C">3.11</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">14</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">baseos</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">111</span><span style="color: #EEFFFF"> k</span></span> <span class="line"><span style="color: #EEFFFF"> python3</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">pycparser noarch </span><span style="color: #F78C6C">2.20</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">6</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">baseos</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">139</span><span style="color: #EEFFFF"> k</span></span> <span class="line"><span style="color: #EEFFFF"> python3</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">pyparsing noarch </span><span style="color: #F78C6C">2.4</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">7</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">9</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">baseos</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">154</span><span style="color: #EEFFFF"> k</span></span> <span class="line"><span style="color: #EEFFFF"> python3</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">resolvelib noarch </span><span style="color: #F78C6C">0.5</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">4</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">5</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">appstream</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">38</span><span style="color: #EEFFFF"> k</span></span> <span class="line"><span style="color: #EEFFFF"> sshpass x86_64 </span><span style="color: #F78C6C">1.09</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">4</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">el9 rhel</span><span style="color: #89DDFF">-</span><span style="color: #F78C6C">9</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">for</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">x86_64</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">appstream</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">rpms </span><span style="color: #F78C6C">30</span><span style="color: #EEFFFF"> k</span></span> <span class="line"></span> |
Verify the Ansible version
1 2 3 4 5 6 7 8 9 10 |
<span class="line"><span style="color: #EEFFFF">[root@aap </span><span style="color: #89DDFF">~</span><span style="color: #EEFFFF">]# ansible </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">version</span></span> <span class="line"><span style="color: #EEFFFF">ansible [core </span><span style="color: #F78C6C">2.14</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">9</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> config file </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">etc</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">ansible</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">ansible</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">cfg</span></span> <span class="line"><span style="color: #EEFFFF"> configured </span><span style="color: #C792EA">module</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">search</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">path</span><span style="color: #EEFFFF"> = [</span><span style="color: #89DDFF">'</span><span style="color: #C3E88D">/root/.ansible/plugins/modules</span><span style="color: #89DDFF">'</span><span style="color: #EEFFFF">, </span><span style="color: #89DDFF">'</span><span style="color: #C3E88D">/usr/share/ansible/plugins/modules</span><span style="color: #89DDFF">'</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">ansible</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">python</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">module</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">location</span><span style="color: #EEFFFF"> = /</span><span style="color: #FFCB6B">usr</span><span style="color: #EEFFFF">/</span><span style="color: #FFCB6B">lib</span><span style="color: #EEFFFF">/</span><span style="color: #FFCB6B">python3</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">9/</span><span style="color: #FFCB6B">site</span><span style="color: #EEFFFF">-</span><span style="color: #FFCB6B">packages</span><span style="color: #EEFFFF">/</span><span style="color: #FFCB6B">ansible</span></span> <span class="line"><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">ansible</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">collection</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">location</span><span style="color: #EEFFFF"> = /</span><span style="color: #FFCB6B">root</span><span style="color: #EEFFFF">/</span><span style="color: #89DDFF">.</span><span style="color: #FFCB6B">ansible</span><span style="color: #EEFFFF">/</span><span style="color: #FFCB6B">collections</span><span style="color: #EEFFFF">:/</span><span style="color: #FFCB6B">usr</span><span style="color: #EEFFFF">/</span><span style="color: #FFCB6B">share</span><span style="color: #EEFFFF">/</span><span style="color: #FFCB6B">ansible</span><span style="color: #EEFFFF">/</span><span style="color: #FFCB6B">collections</span></span> <span class="line"><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">executable</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">location</span><span style="color: #EEFFFF"> = /</span><span style="color: #FFCB6B">usr</span><span style="color: #EEFFFF">/</span><span style="color: #FFCB6B">bin</span><span style="color: #EEFFFF">/</span><span style="color: #FFCB6B">ansible</span></span> <span class="line"><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">python</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">version</span><span style="color: #EEFFFF"> = 3</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">9</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">18 (</span><span style="color: #FFCB6B">main</span><span style="color: #EEFFFF">, </span><span style="color: #FFCB6B">Jan</span><span style="color: #EEFFFF"> 4 2024, 00:00:00) [</span><span style="color: #FFCB6B">GCC</span><span style="color: #EEFFFF"> 11</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">4</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">1 20230605 (</span><span style="color: #FFCB6B">Red</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">Hat</span><span style="color: #EEFFFF"> 11</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">4</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">1-2)] (/</span><span style="color: #FFCB6B">usr</span><span style="color: #EEFFFF">/</span><span style="color: #FFCB6B">bin</span><span style="color: #EEFFFF">/</span><span style="color: #FFCB6B">python3</span><span style="color: #EEFFFF">)</span></span> <span class="line"><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">jinja</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">version</span><span style="color: #EEFFFF"> = 3</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">1</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">2</span></span> <span class="line"><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">libyaml</span><span style="color: #EEFFFF"> = </span><span style="color: #FFCB6B">True</span></span> |
Verify the Python version
1 2 3 |
<span class="line"><span style="color: #EEFFFF">[root@aap </span><span style="color: #89DDFF">~</span><span style="color: #EEFFFF">]# python </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">version</span></span> <span class="line"><span style="color: #EEFFFF">Python </span><span style="color: #F78C6C">3.9</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">18</span></span> <span class="line"><span style="color: #EEFFFF">[root@aap </span><span style="color: #89DDFF">~</span><span style="color: #EEFFFF">]#</span></span> |
We will need to create a normal Linux user for Ansible Node Management. In this example, i’ve choosen ariaadm.
1 2 3 4 5 6 7 |
<span class="line"><span style="color: #EEFFFF">[root@aap </span><span style="color: #89DDFF">~</span><span style="color: #EEFFFF">]# useradd ariaadm</span></span> <span class="line"><span style="color: #EEFFFF">[root@aap </span><span style="color: #89DDFF">~</span><span style="color: #EEFFFF">]# passwd ariaadm</span></span> <span class="line"><span style="color: #EEFFFF">Changing password for user ariaadm</span><span style="color: #89DDFF">.</span></span> <span class="line"><span style="color: #EEFFFF">New </span><span style="color: #FFCB6B">password</span><span style="color: #89DDFF">:</span></span> <span class="line"><span style="color: #EEFFFF">Retype </span><span style="color: #89DDFF">new</span><span style="color: #EEFFFF"> password:</span></span> <span class="line"><span style="color: #FFCB6B">passwd</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> all authentication tokens updated successfully</span><span style="color: #89DDFF">.</span></span> <span class="line"></span> |
We will allow Linux users to run any commands anywhere by adding an entry in /etc/sudoers, this entry should be an all-managed server as well for Ansible to execute commands as a admin user if necessary.
1 2 |
<span class="line"><span style="color: #EEFFFF">## Allow root to run any commands anywhere without prompting for password</span></span> <span class="line"><span style="color: #EEFFFF">ariaadm ALL</span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF">(ALL) </span><span style="color: #FFCB6B">NOPASSWD</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF">ALL</span></span> |
The below option can be used in case we wish to input a password following the execution of an Ansible command
1 2 |
<span class="line"><span style="color: #E1E4E8">## Allow root to run any commands anywhere without prompting for password</span></span> <span class="line"><span style="color: #E1E4E8">ariaadm </span><span style="color: #79B8FF">ALL</span><span style="color: #F97583">=</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">ALL</span><span style="color: #E1E4E8">) </span><span style="color: #B392F0">PASSWD</span><span style="color: #E1E4E8">:</span><span style="color: #79B8FF">ALL</span></span> |
Generate SSH keys for the ariaadm user
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<span class="line"><span style="color: #EEFFFF">[ariaadm@aap root]$ ssh</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">keygen</span></span> <span class="line"><span style="color: #EEFFFF">Generating public</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">private rsa key pair</span><span style="color: #89DDFF">.</span></span> <span class="line"><span style="color: #EEFFFF">Enter file </span><span style="color: #89DDFF">in</span><span style="color: #EEFFFF"> which to save the </span><span style="color: #82AAFF">key</span><span style="color: #EEFFFF"> (</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">home</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">ariaadm</span><span style="color: #89DDFF">/.</span><span style="color: #EEFFFF">ssh</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">id_rsa):</span></span> <span class="line"><span style="color: #EEFFFF">Created directory </span><span style="color: #89DDFF">'</span><span style="color: #C3E88D">/home/ariaadm/.ssh</span><span style="color: #89DDFF">'</span><span style="color: #89DDFF">.</span></span> <span class="line"><span style="color: #EEFFFF">Enter </span><span style="color: #82AAFF">passphrase</span><span style="color: #EEFFFF"> (empty for no passphrase):</span></span> <span class="line"><span style="color: #EEFFFF">Enter same passphrase </span><span style="color: #FFCB6B">again</span><span style="color: #89DDFF">:</span></span> <span class="line"><span style="color: #EEFFFF">Your identification has been saved </span><span style="color: #89DDFF">in</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">home</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">ariaadm</span><span style="color: #89DDFF">/.</span><span style="color: #EEFFFF">ssh</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">id_rsa</span></span> <span class="line"><span style="color: #EEFFFF">Your public key has been saved </span><span style="color: #89DDFF">in</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">home</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">ariaadm</span><span style="color: #89DDFF">/.</span><span style="color: #EEFFFF">ssh</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">id_rsa</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">pub</span></span> <span class="line"><span style="color: #EEFFFF">The key fingerprint </span><span style="color: #FFCB6B">is</span><span style="color: #89DDFF">:</span></span> <span class="line"><span style="color: #FFCB6B">SHA256</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF">jecHW7K35a4a</span><span style="color: #89DDFF">+</span><span style="color: #EEFFFF">s3JVwdNW5G</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">X9YdpGkNjNGX2fhnp4k ariaadm@aap</span></span> <span class="line"><span style="color: #EEFFFF">The key</span><span style="color: #89DDFF">'</span><span style="color: #C3E88D">s randomart image is:</span></span> <span class="line"><span style="color: #89DDFF">+---</span><span style="color: #EEFFFF">[RSA </span><span style="color: #F78C6C">3072</span><span style="color: #EEFFFF">]</span><span style="color: #89DDFF">----+</span></span> <span class="line"><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">.=</span><span style="color: #EEFFFF"> o</span><span style="color: #89DDFF">*|</span></span> <span class="line"><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">+.*+|</span></span> <span class="line"><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> B</span><span style="color: #89DDFF">++|</span></span> <span class="line"><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> o </span><span style="color: #89DDFF">+.+</span><span style="color: #EEFFFF">B</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> S </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> o</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF">B</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> o </span><span style="color: #89DDFF">*</span><span style="color: #EEFFFF">E o</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">B</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> o </span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">o</span><span style="color: #89DDFF">+|</span></span> <span class="line"><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF"> B </span><span style="color: #89DDFF">=.</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">.|</span></span> <span class="line"><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">..</span><span style="color: #EEFFFF">o</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">B</span><span style="color: #89DDFF">+</span><span style="color: #EEFFFF">o </span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #89DDFF">+----</span><span style="color: #EEFFFF">[SHA256]</span><span style="color: #89DDFF">-----+</span></span> <span class="line"><span style="color: #EEFFFF">[ariaadm@aap root]$</span></span> |
Copy the ssh key on every Ansible-managed node for us to do password-less login to all servers managed with Ansible via SSH.
1 2 3 4 5 6 7 8 9 10 11 12 |
<span class="line"><span style="color: #EEFFFF">[ariaadm@aap root]$ ssh</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">copy</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">id ariaadm@webserver01</span></span> <span class="line"><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">usr</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">bin</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">ssh</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">copy</span><span style="color: #89DDFF">-</span><span style="color: #FFCB6B">id</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">INFO</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> Source </span><span style="color: #89DDFF">of</span><span style="color: #EEFFFF"> </span><span style="color: #82AAFF">key</span><span style="color: #EEFFFF">(s) to be </span><span style="color: #FFCB6B">installed</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">/home/ariaadm/.ssh/id_rsa.pub</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">usr</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">bin</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">ssh</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">copy</span><span style="color: #89DDFF">-</span><span style="color: #FFCB6B">id</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">INFO</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> attempting to log </span><span style="color: #89DDFF">in</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF; font-style: italic">with</span><span style="color: #EEFFFF"> the </span><span style="color: #89DDFF">new</span><span style="color: #EEFFFF"> </span><span style="color: #82AAFF">key</span><span style="color: #EEFFFF">(s)</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> to filter out any that are already installed</span></span> <span class="line"><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">usr</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">bin</span><span style="color: #89DDFF">/</span><span style="color: #EEFFFF">ssh</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">copy</span><span style="color: #89DDFF">-</span><span style="color: #FFCB6B">id</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">INFO</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">1</span><span style="color: #EEFFFF"> </span><span style="color: #82AAFF">key</span><span style="color: #EEFFFF">(s) remain to be installed </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF; font-style: italic">if</span><span style="color: #EEFFFF"> you are prompted now it is to install the </span><span style="color: #89DDFF">new</span><span style="color: #EEFFFF"> keys</span></span> <span class="line"><span style="color: #EEFFFF">ariaadm@webserver01</span><span style="color: #89DDFF">'</span><span style="color: #C3E88D">s password:</span></span> <span class="line"></span> <span class="line"><span style="color: #EEFFFF">Number </span><span style="color: #89DDFF">of</span><span style="color: #EEFFFF"> </span><span style="color: #82AAFF">key</span><span style="color: #EEFFFF">(s) </span><span style="color: #FFCB6B">added</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">1</span></span> <span class="line"></span> <span class="line"><span style="color: #EEFFFF">Now </span><span style="color: #89DDFF; font-style: italic">try</span><span style="color: #EEFFFF"> logging into the machine</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF; font-style: italic">with</span><span style="color: #EEFFFF">: </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">ssh 'ariaadm@webserver01'</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF">and check to make sure that only the </span><span style="color: #82AAFF">key</span><span style="color: #EEFFFF">(s) you wanted were added</span><span style="color: #89DDFF">.</span></span> <span class="line"></span> <span class="line"></span> |
The main configuration files on ansible are under /etc/ansible. The two important files in here are the /etc/ansible/hosts (also known as inventory file), etc/ansible/ansible.cfg ( also known as config file). Update lists of hosts to be managed by ansible into an inventory file or the host’s file below.The default location for the host inventory file is /etc/ansible/hosts.
Create an inventory file and add all the hosts that are managed by Ansible in this format.
1 2 3 4 5 6 7 8 9 |
<span class="line"><span style="color: #EEFFFF">## All the hosts managed by Ansible Automation</span></span> <span class="line"><span style="color: #EEFFFF">[database]</span></span> <span class="line"><span style="color: #EEFFFF">db</span></span> <span class="line"><span style="color: #EEFFFF">[webs]</span></span> <span class="line"><span style="color: #EEFFFF">webserver02</span></span> <span class="line"><span style="color: #EEFFFF">webserver01</span></span> <span class="line"><span style="color: #EEFFFF">[elb]</span></span> <span class="line"><span style="color: #EEFFFF">haproxy</span></span> <span class="line"></span> |
Tweak the following parameter in Ansible config file /etc/ansible.cfg to enable privilege escalation that will enable us to run commands as root
1 2 3 4 5 6 7 8 9 |
<span class="line"><span style="color: #575279">[</span><span style="color: #575279; font-style: italic">privilege_escalation</span><span style="color: #575279">]</span></span> <span class="line"><span style="color: #575279; font-style: italic">become</span><span style="color: #286983">=</span><span style="color: #D7827E">true</span></span> <span class="line"><span style="color: #575279; font-style: italic">become_method</span><span style="color: #286983">=</span><span style="color: #575279; font-style: italic">sudo</span></span> <span class="line"><span style="color: #575279; font-style: italic">become_user</span><span style="color: #286983">=</span><span style="color: #575279; font-style: italic">root</span></span> <span class="line"><span style="color: #575279; font-style: italic">become_ask_pass</span><span style="color: #286983">=</span><span style="color: #575279; font-style: italic">False</span></span> <span class="line"></span> <span class="line"><span style="color: #575279; font-style: italic">host_key_checking</span><span style="color: #286983">=</span><span style="color: #D7827E">false</span></span> <span class="line"><span style="color: #575279; font-style: italic">remote_user</span><span style="color: #575279"> </span><span style="color: #286983">=</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">ariaadm</span></span> <span class="line"><span style="color: #575279; font-style: italic">ask_pass</span><span style="color: #575279"> </span><span style="color: #286983">=</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">False</span></span> |
Run the following Ansible command to perform an Ansible check from the control node to the managed node
1 2 3 4 5 6 7 8 9 10 |
<span class="line"></span> <span class="line"><span style="color: #EEFFFF">## Syntax </span><span style="color: #89DDFF">of</span><span style="color: #EEFFFF"> command </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">m </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF"> stands for </span><span style="color: #89DDFF">module,</span><span style="color: #EEFFFF"> command </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF"> </span><span style="color: #C792EA">module</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">name</span><span style="color: #EEFFFF"> , -</span><span style="color: #FFCB6B">a</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">append</span><span style="color: #EEFFFF"> , </span><span style="color: #FFCB6B">command</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">to</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">run</span><span style="color: #EEFFFF">, </span><span style="color: #FFCB6B">target</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">group</span><span style="color: #EEFFFF"> </span></span> <span class="line"></span> <span class="line"><span style="color: #EEFFFF">[</span><span style="color: #FFCB6B">ariaadm</span><span style="color: #EEFFFF">@</span><span style="color: #FFCB6B">aap</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">ansible</span><span style="color: #EEFFFF">]</span><span style="color: #FFCB6B">$</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">ansible</span><span style="color: #EEFFFF"> -</span><span style="color: #FFCB6B">m</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">command</span><span style="color: #EEFFFF"> -</span><span style="color: #FFCB6B">a</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">uptime</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">webs</span></span> <span class="line"><span style="color: #FFCB6B">webserver02</span><span style="color: #EEFFFF"> | </span><span style="color: #FFCB6B">CHANGED</span><span style="color: #EEFFFF"> | </span><span style="color: #FFCB6B">rc</span><span style="color: #EEFFFF">=0 >></span></span> <span class="line"><span style="color: #EEFFFF"> 16:26:00 </span><span style="color: #FFCB6B">up</span><span style="color: #EEFFFF"> 2:09, 1 </span><span style="color: #FFCB6B">user</span><span style="color: #EEFFFF">, </span><span style="color: #FFCB6B">load</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">average</span><span style="color: #EEFFFF">: 0</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">10, 0</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">30, 0</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">20</span></span> <span class="line"><span style="color: #FFCB6B">webserver01</span><span style="color: #EEFFFF"> | </span><span style="color: #FFCB6B">CHANGED</span><span style="color: #EEFFFF"> | </span><span style="color: #FFCB6B">rc</span><span style="color: #EEFFFF">=0 >></span></span> <span class="line"><span style="color: #EEFFFF"> 16:26:00 </span><span style="color: #FFCB6B">up</span><span style="color: #EEFFFF"> 2:09, 1 </span><span style="color: #FFCB6B">user</span><span style="color: #EEFFFF">, </span><span style="color: #FFCB6B">load</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">average</span><span style="color: #EEFFFF">: 0</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">07, 0</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">30, 0</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">21</span></span> <span class="line"><span style="color: #EEFFFF">[</span><span style="color: #FFCB6B">ariaadm</span><span style="color: #EEFFFF">@</span><span style="color: #FFCB6B">aap</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">ansible</span><span style="color: #EEFFFF">]</span><span style="color: #FFCB6B">$</span><span style="color: #EEFFFF"> </span></span> <span class="line"></span> |
Prefix the above Ansible command with –become to perform an Ansible check from the control node to the managed node elevating us as a root user.
1 2 3 4 5 6 7 8 9 |
<span class="line"><span style="color: #EEFFFF">[ariaadm@aap ansible]$ ansible </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">m command </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">a </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">lvs</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF"> webs </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">become</span></span> <span class="line"><span style="color: #EEFFFF">webserver02 </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> CHANGED </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> rc</span><span style="color: #89DDFF">=</span><span style="color: #F78C6C">0</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">>></span></span> <span class="line"><span style="color: #EEFFFF"> LV VG Attr LSize Pool Origin Data</span><span style="color: #89DDFF">%</span><span style="color: #EEFFFF"> Meta</span><span style="color: #89DDFF">%</span><span style="color: #EEFFFF"> Move Log Cpy</span><span style="color: #89DDFF">%</span><span style="color: #EEFFFF">Sync Convert</span></span> <span class="line"><span style="color: #EEFFFF"> root rhel_unknown </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">wi</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">ao</span><span style="color: #89DDFF">----</span><span style="color: #EEFFFF"> 11</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">91g </span></span> <span class="line"><span style="color: #EEFFFF"> swap rhel_unknown </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">wi</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">ao</span><span style="color: #89DDFF">----</span><span style="color: #EEFFFF"> 1</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">50g </span></span> <span class="line"><span style="color: #EEFFFF">webserver01 </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> CHANGED </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF"> rc</span><span style="color: #89DDFF">=</span><span style="color: #F78C6C">0</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">>></span></span> <span class="line"><span style="color: #EEFFFF"> LV VG Attr LSize Pool Origin Data</span><span style="color: #89DDFF">%</span><span style="color: #EEFFFF"> Meta</span><span style="color: #89DDFF">%</span><span style="color: #EEFFFF"> Move Log Cpy</span><span style="color: #89DDFF">%</span><span style="color: #EEFFFF">Sync Convert</span></span> <span class="line"><span style="color: #EEFFFF"> root rhel_unknown </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">wi</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">ao</span><span style="color: #89DDFF">----</span><span style="color: #EEFFFF"> 11</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">91g </span></span> <span class="line"><span style="color: #EEFFFF"> swap rhel_unknown </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">wi</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">ao</span><span style="color: #89DDFF">----</span><span style="color: #EEFFFF"> 1</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">50g </span></span> |
If we wish to type a password following the execution of a command we use the option K
1 2 3 4 5 6 7 8 9 10 11 12 |
<span class="line"><span style="color: #575279">[</span><span style="color: #575279; font-style: italic">ariaadm</span><span style="color: #575279">@</span><span style="color: #575279; font-style: italic">aap</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">ansible</span><span style="color: #575279">]</span><span style="color: #575279; font-style: italic">$</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">ansible</span><span style="color: #575279"> </span><span style="color: #286983">-</span><span style="color: #575279; font-style: italic">m</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">command</span><span style="color: #575279"> </span><span style="color: #286983">-</span><span style="color: #575279; font-style: italic">a</span><span style="color: #575279"> </span><span style="color: #EA9D34">"lvs"</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">webs</span><span style="color: #575279"> </span><span style="color: #286983">--</span><span style="color: #575279; font-style: italic">become</span><span style="color: #575279"> </span><span style="color: #286983">-</span><span style="color: #575279; font-style: italic">K</span><span style="color: #575279"> </span></span> <span class="line"><span style="color: #575279; font-style: italic">BECOME</span><span style="color: #575279"> </span><span style="color: #D7827E">password</span><span style="color: #797593">:</span><span style="color: #575279"> </span></span> <span class="line"><span style="color: #575279; font-style: italic">webserver01</span><span style="color: #575279"> </span><span style="color: #286983">|</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">CHANGED</span><span style="color: #575279"> </span><span style="color: #286983">|</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">rc</span><span style="color: #286983">=</span><span style="color: #D7827E">0</span><span style="color: #575279"> </span><span style="color: #286983">>></span></span> <span class="line"><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">LV</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">VG</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Attr</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">LSize</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Pool</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Origin</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Data</span><span style="color: #286983">%</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Meta</span><span style="color: #286983">%</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Move</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Log</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Cpy</span><span style="color: #286983">%</span><span style="color: #575279; font-style: italic">Sync</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Convert</span></span> <span class="line"><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">root</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">rhel_unknown</span><span style="color: #575279"> </span><span style="color: #286983">-</span><span style="color: #575279; font-style: italic">wi</span><span style="color: #286983">-</span><span style="color: #575279; font-style: italic">ao</span><span style="color: #286983">----</span><span style="color: #575279"> 11</span><span style="color: #286983">.</span><span style="color: #575279">91</span><span style="color: #575279; font-style: italic">g</span><span style="color: #575279"> </span></span> <span class="line"><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">swap</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">rhel_unknown</span><span style="color: #575279"> </span><span style="color: #286983">-</span><span style="color: #575279; font-style: italic">wi</span><span style="color: #286983">-</span><span style="color: #575279; font-style: italic">ao</span><span style="color: #286983">----</span><span style="color: #575279"> 1</span><span style="color: #286983">.</span><span style="color: #575279">50</span><span style="color: #575279; font-style: italic">g</span><span style="color: #575279"> </span></span> <span class="line"><span style="color: #575279; font-style: italic">webserver02</span><span style="color: #575279"> </span><span style="color: #286983">|</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">CHANGED</span><span style="color: #575279"> </span><span style="color: #286983">|</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">rc</span><span style="color: #286983">=</span><span style="color: #D7827E">0</span><span style="color: #575279"> </span><span style="color: #286983">>></span></span> <span class="line"><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">LV</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">VG</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Attr</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">LSize</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Pool</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Origin</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Data</span><span style="color: #286983">%</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Meta</span><span style="color: #286983">%</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Move</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Log</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Cpy</span><span style="color: #286983">%</span><span style="color: #575279; font-style: italic">Sync</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">Convert</span></span> <span class="line"><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">root</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">rhel_unknown</span><span style="color: #575279"> </span><span style="color: #286983">-</span><span style="color: #575279; font-style: italic">wi</span><span style="color: #286983">-</span><span style="color: #575279; font-style: italic">ao</span><span style="color: #286983">----</span><span style="color: #575279"> 11</span><span style="color: #286983">.</span><span style="color: #575279">91</span><span style="color: #575279; font-style: italic">g</span><span style="color: #575279"> </span></span> <span class="line"><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">swap</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">rhel_unknown</span><span style="color: #575279"> </span><span style="color: #286983">-</span><span style="color: #575279; font-style: italic">wi</span><span style="color: #286983">-</span><span style="color: #575279; font-style: italic">ao</span><span style="color: #286983">----</span><span style="color: #575279"> 1</span><span style="color: #286983">.</span><span style="color: #575279">50</span><span style="color: #575279; font-style: italic">g</span><span style="color: #575279"> </span></span> <span class="line"><span style="color: #575279">[</span><span style="color: #575279; font-style: italic">ariaadm</span><span style="color: #575279">@</span><span style="color: #575279; font-style: italic">aap</span><span style="color: #575279"> </span><span style="color: #575279; font-style: italic">ansible</span><span style="color: #575279">]</span><span style="color: #575279; font-style: italic">$</span><span style="color: #575279"> </span></span> <span class="line"></span> |