<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohammad</title>
    <description>The latest articles on DEV Community by Mohammad (@mohammadtb).</description>
    <link>https://dev.to/mohammadtb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1192966%2Fd2726bee-64a1-448e-ad15-c4e5b64f2a2e.jpeg</url>
      <title>DEV Community: Mohammad</title>
      <link>https://dev.to/mohammadtb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohammadtb"/>
    <language>en</language>
    <item>
      <title>Mastering Automation with Ansible</title>
      <dc:creator>Mohammad</dc:creator>
      <pubDate>Tue, 24 Oct 2023 16:44:38 +0000</pubDate>
      <link>https://dev.to/mohammadtb/mastering-automation-with-ansible-1k5</link>
      <guid>https://dev.to/mohammadtb/mastering-automation-with-ansible-1k5</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What is Ansible ?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gErt7LxV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0wewri33pugd3nase9zt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gErt7LxV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0wewri33pugd3nase9zt.png" alt="Image description" width="690" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ansible is an open-source automation tool that is used for configuration management, application deployment, task automation, and orchestration. It simplifies the management of IT infrastructure by allowing you to define and automate the tasks and processes required to maintain and deploy software, configure systems, and manage various resources in a consistent and efficient manner.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ansible Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ax2czF6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qudb310r76bvfcwllxwc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ax2czF6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qudb310r76bvfcwllxwc.png" alt="Image description" width="800" height="557"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At a high level, Ansible works by connecting to target hosts (remote systems) and executing tasks defined in playbooks. Here's a minimal overview of how Ansible operates:&lt;/p&gt;

&lt;p&gt;Playbook Creation: You create a playbook using a YAML-formatted file. The playbook contains a list of tasks and specifies which hosts or groups of hosts these tasks should run on.&lt;/p&gt;

&lt;p&gt;Inventory Definition: You define an inventory, which lists the hosts or groups of hosts that Ansible will manage. This can be done in an inventory file or using dynamic inventory sources.&lt;/p&gt;

&lt;p&gt;Playbook Execution: You run the Ansible playbook on a control node. Ansible connects to the target hosts via SSH (for Unix-based systems) or WinRM (for Windows-based systems) to execute tasks. It uses the SSH or WinRM credentials specified in the inventory file.&lt;/p&gt;

&lt;p&gt;Task Execution: Ansible iterates through the tasks in the playbook, executing them one by one on the target hosts. Each task corresponds to a module, which performs a specific action (e.g., installing software, configuring a service, copying files).&lt;/p&gt;

&lt;p&gt;Gathering Facts: Before executing tasks, Ansible typically gathers system information or "facts" from the target hosts. These facts can be used as variables in the playbook.&lt;/p&gt;

&lt;p&gt;Idempotent Execution: Ansible is idempotent, which means it ensures the desired state of the system, and running the same playbook multiple times will not have unintended side effects. It will only make necessary changes to achieve the desired state.&lt;/p&gt;

&lt;p&gt;Reporting: Ansible provides feedback and reports on the success or failure of each task on each target host, allowing you to monitor the automation process.&lt;/p&gt;

&lt;p&gt;Handlers: If tasks trigger handlers (e.g., a service restart), those handlers are executed at the appropriate point in the playbook.&lt;/p&gt;

&lt;p&gt;Completion: Once all tasks are executed, the Ansible playbook completes, and you receive a summary of the results, indicating which tasks were successful and which failed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ansible Installation as a docker container
&lt;/h2&gt;

&lt;p&gt;You can run Ansible as a Docker container to use it without installing it directly on your local machine. Here's how to set up Ansible inside a Docker container:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Pull the Ansible Docker Image:&lt;/strong&gt; You can use the official Ansible Docker image from Docker Hub. Pull the image using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker pull ansible/ansible:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command fetches the latest Ansible image from Docker Hub.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Run the Ansible Container:&lt;/strong&gt; You can start an interactive session in the Ansible container to run Ansible commands. Here's a basic command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker run &lt;span class="nt"&gt;-it&lt;/span&gt; &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; /path/to/your/ansible/playbooks:/ansible/playbooks ansible/ansible:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-it&lt;/code&gt;: This flag allows you to interact with the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--rm&lt;/code&gt;: This flag removes the container after you exit the session.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-v /path/to/your/ansible/playbooks:/ansible/playbooks&lt;/code&gt;: This flag mounts your local Ansible playbooks directory into the container.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Replace &lt;code&gt;/path/to/your/ansible/playbooks&lt;/code&gt; with the actual path to your Ansible playbooks on your local machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Inside the Ansible Container:&lt;/strong&gt; Once inside the container, you can run Ansible commands as you would on a regular system. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ansible-playbook /ansible/playbooks/your_playbook.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command runs an Ansible playbook located in the mounted directory.&lt;/p&gt;

&lt;p&gt;By running Ansible inside a Docker container, you keep your local machine clean from Ansible installations and dependencies. It also allows you to easily manage different versions of Ansible for various projects by pulling different Docker images as needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ansible playbooks
&lt;/h2&gt;

&lt;p&gt;Ansible playbooks are configuration management and automation files written in YAML format. Playbooks define a set of tasks, roles, and variables to be executed on one or more target hosts. Here's a simple example of an Ansible playbook to give you an introduction to how playbooks work.&lt;/p&gt;

&lt;p&gt;Suppose you want to create a playbook that installs and configures the Nginx web server on a set of remote servers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Inventory File (hosts.ini):&lt;/strong&gt; Create an Ansible inventory file listing the target servers you want to manage. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[web_servers]&lt;/span&gt;
&lt;span class="err"&gt;server1&lt;/span&gt; &lt;span class="py"&gt;ansible_host&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;webserver1.example.com&lt;/span&gt;
&lt;span class="err"&gt;server2&lt;/span&gt; &lt;span class="py"&gt;ansible_host&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;webserver2.example.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Ansible Playbook (webserver.yml):&lt;/strong&gt; Create an Ansible playbook to install and configure Nginx on the target servers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install and Configure Nginx&lt;/span&gt;
  &lt;span class="na"&gt;hosts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;web_servers&lt;/span&gt;
  &lt;span class="na"&gt;become&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yes&lt;/span&gt;
  &lt;span class="na"&gt;tasks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Update package cache&lt;/span&gt;
      &lt;span class="na"&gt;package&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;item&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}"&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;latest&lt;/span&gt;
      &lt;span class="na"&gt;loop&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;
      &lt;span class="na"&gt;when&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ansible_os_family == 'Debian'&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install Nginx (for Red Hat/CentOS)&lt;/span&gt;
      &lt;span class="na"&gt;yum&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;latest&lt;/span&gt;
      &lt;span class="na"&gt;when&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ansible_os_family == 'RedHat'&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Start Nginx service&lt;/span&gt;
      &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;started&lt;/span&gt;
        &lt;span class="na"&gt;enabled&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This playbook consists of the following elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;name:&lt;/strong&gt; A description of the playbook.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;hosts:&lt;/strong&gt; The group of hosts from the inventory file that this playbook targets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;become:&lt;/strong&gt; This indicates that tasks should be run with sudo privileges.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;tasks:&lt;/strong&gt; A list of tasks to perform on the target hosts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this example, we first update the package cache for Debian-based systems, then install Nginx using the &lt;code&gt;package&lt;/code&gt; module. For Red Hat/CentOS-based systems, we use the &lt;code&gt;yum&lt;/code&gt; module to install Nginx. Finally, we use the &lt;code&gt;service&lt;/code&gt; module to start and enable the Nginx service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Running the Playbook:&lt;/strong&gt; You can execute the playbook using the &lt;code&gt;ansible-playbook&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible-playbook &lt;span class="nt"&gt;-i&lt;/span&gt; hosts.ini webserver.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will apply the tasks defined in the playbook to the hosts listed in the inventory file.&lt;/p&gt;

&lt;p&gt;Of course, this is a basic example. Ansible playbooks can become much more complex as you include variables, roles, conditionals, and more advanced tasks. You can also use &lt;a href="https://galaxy.ansible.com/ui/"&gt;Ansible Galaxy&lt;/a&gt; to find and reuse pre-made roles to simplify your playbook development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ansible Install MySQL
&lt;/h2&gt;

&lt;p&gt;To install MySQL using Ansible, you'll need to create an Ansible playbook that defines the tasks required to install MySQL on your target servers. Here's a basic example of how you can do this:&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;1. Inventory File (hosts.ini):&lt;br&gt;
*&lt;/em&gt; Create an Ansible inventory file that lists the target servers where you want to install MySQL. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[mysql_servers]&lt;/span&gt;
&lt;span class="err"&gt;server1&lt;/span&gt; &lt;span class="py"&gt;ansible_host&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;your_server1_ip&lt;/span&gt;
&lt;span class="err"&gt;server2&lt;/span&gt; &lt;span class="py"&gt;ansible_host&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;your_server2_ip&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Ansible Playbook (install_mysql.yml):&lt;/strong&gt; Create an Ansible playbook that installs MySQL. Here's an example playbook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install MySQL&lt;/span&gt;
  &lt;span class="na"&gt;hosts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysql_servers&lt;/span&gt;
  &lt;span class="na"&gt;become&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yes&lt;/span&gt;
  &lt;span class="na"&gt;tasks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Update apt package cache (for Debian/Ubuntu)&lt;/span&gt;
      &lt;span class="na"&gt;apt&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;update_cache&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yes&lt;/span&gt;
      &lt;span class="na"&gt;when&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ansible_os_family == 'Debian'&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install MySQL Server&lt;/span&gt;
      &lt;span class="na"&gt;apt&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysql-server&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;present&lt;/span&gt;
      &lt;span class="na"&gt;when&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ansible_os_family == 'Debian'&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Start MySQL Service&lt;/span&gt;
      &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysql&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;started&lt;/span&gt;
      &lt;span class="na"&gt;when&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ansible_os_family == 'Debian'&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install MySQL Server (for Red Hat/CentOS)&lt;/span&gt;
      &lt;span class="na"&gt;yum&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysql-server&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;present&lt;/span&gt;
      &lt;span class="na"&gt;when&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ansible_os_family == 'RedHat'&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Start MySQL Service (for Red Hat/CentOS)&lt;/span&gt;
      &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysqld&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;started&lt;/span&gt;
      &lt;span class="na"&gt;when&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ansible_os_family == 'RedHat'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this playbook, we use the &lt;code&gt;apt&lt;/code&gt; module for Debian/Ubuntu-based systems and the &lt;code&gt;yum&lt;/code&gt; module for Red Hat/CentOS-based systems to install MySQL. The &lt;code&gt;service&lt;/code&gt; module is used to ensure that the MySQL service is started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Running the Playbook:&lt;/strong&gt; You can execute the playbook using the &lt;code&gt;ansible-playbook&lt;/code&gt; command, specifying the inventory file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible-playbook &lt;span class="nt"&gt;-i&lt;/span&gt; hosts.ini install_mysql.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1gCE1foz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g8zbsgljmf28c89vrrar.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1gCE1foz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g8zbsgljmf28c89vrrar.jpg" alt="Image description" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ansible is an open-source automation tool used for configuration management, application deployment, and task automation. It simplifies IT infrastructure management by allowing you to define and automate tasks in a structured manner. Ansible operates through playbooks, inventory management, and task execution. You can run Ansible in a Docker container for a clean local environment and efficient management of different Ansible versions. Ansible playbooks, written in YAML, automate tasks on target hosts, making it a versatile tool for various automation needs, from package installation to complex configurations, ensuring consistent and reliable infrastructure management.&lt;/p&gt;

</description>
      <category>ansible</category>
      <category>devops</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Minikube and Kubectl Installation Guide: Deploy Kubernetes Clusters in a Few Simple Steps :</title>
      <dc:creator>Mohammad</dc:creator>
      <pubDate>Tue, 24 Oct 2023 15:43:26 +0000</pubDate>
      <link>https://dev.to/mohammadtb/minikube-and-kubectl-installation-guide-deploy-kubernetes-clusters-in-a-few-simple-steps--306g</link>
      <guid>https://dev.to/mohammadtb/minikube-and-kubectl-installation-guide-deploy-kubernetes-clusters-in-a-few-simple-steps--306g</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_b9IOsy3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jkt5kigplhfphfbiplls.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_b9IOsy3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jkt5kigplhfphfbiplls.jpg" alt="Image description" width="800" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When it comes to working with Kubernetes, two essential tools are Minikube and Kubectl. Minikube is a tool that allows you to create a local Kubernetes cluster for development and testing, while Kubectl is the command-line tool for managing Kubernetes clusters. In this article, we will guide you through the steps to install Minikube and Kubectl on your machine, allowing you to dive into the fascinating world of Kubernetes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing Minikube&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first step to working with Minikube is to install it on your system. Here's how to do it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;: Before you start, make sure you have installed a hypervisor such as VirtualBox or KVM because Minikube uses virtual machines to create Kubernetes clusters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;: Follow the installation instructions for Linux:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Download the Minikube executable&lt;/span&gt;
curl &lt;span class="nt"&gt;-LO&lt;/span&gt; https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

&lt;span class="c"&gt;# Make it executable&lt;/span&gt;
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x minikube-linux-amd64
&lt;span class="c"&gt;# Move it to a reachable directory&lt;/span&gt;
&lt;span class="nb"&gt;sudo mv &lt;/span&gt;minikube-linux-amd64 /usr/local/bin/minikube
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Starting Minikube&lt;/strong&gt;: Once Minikube is installed, you can start a local Kubernetes cluster using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;minikube start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Verification&lt;/strong&gt;: To check if your Minikube cluster is running, use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;minikube status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Installing Kubectl&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1/ Download the latest version of &lt;code&gt;kubectl&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   curl &lt;span class="nt"&gt;-LO&lt;/span&gt; &lt;span class="s2"&gt;"https://dl.k8s.io/release/&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;curl &lt;span class="nt"&gt;-L&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; https://dl.k8s.io/release/stable.txt&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;/bin/linux/amd64/kubectl"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2/ Make the &lt;code&gt;kubectl&lt;/code&gt; binary executable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;chmod&lt;/span&gt; +x kubectl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3/ Move the &lt;code&gt;kubectl&lt;/code&gt; binary to a directory included in your system's PATH, so you can run it from anywhere:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;sudo mv &lt;/span&gt;kubectl /usr/local/bin/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4/ Verify the installation by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   kubectl version &lt;span class="nt"&gt;--client&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Verification of Installation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After installing Minikube and Kubectl, make sure everything is working correctly by running some verification commands. You should see a functional Minikube cluster ready for use. Here's how to do it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Checking Minikube Status&lt;/strong&gt;: Use the following command to check if Minikube is running and in what state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;minikube status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kubectl Verification&lt;/strong&gt;: Run the following command to verify that Kubectl is properly configured to connect to your Minikube cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl version &lt;span class="nt"&gt;--short&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Minikube and Kubectl in place, you're ready to create local Kubernetes clusters and explore Kubernetes features.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a Minikube Cluster&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create a Minikube cluster, follow these simple steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Starting the Cluster&lt;/strong&gt;: Use the following command to start a Minikube cluster with default settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;minikube start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Customization&lt;/strong&gt;: You can customize your cluster by specifying options such as the amount of memory and CPU allocated. For example, to create a cluster with 4GB of memory and 2 CPUs, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;minikube start &lt;span class="nt"&gt;--memory&lt;/span&gt; 4096 &lt;span class="nt"&gt;--cpus&lt;/span&gt; 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Stopping the Cluster&lt;/strong&gt;: When you're done, you can stop the cluster with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;minikube stop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using Kubectl&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that your Minikube cluster is active, you can use Kubectl to interact with Kubernetes. Here are some common command examples:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get the List of Nodes&lt;/strong&gt;: To see the list of nodes in your cluster, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get nodes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deploying an Application&lt;/strong&gt;: You can deploy an application in your cluster using a YAML configuration file. For example, to deploy an application named "myapp" from a file named myapp.yaml, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; myapp.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Get Information About Resources&lt;/strong&gt;: You can get detailed information about Kubernetes resources. For example, to get information about pods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get pods
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how you can install, configure, and start using Minikube and Kubectl to work with Kubernetes on your local machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advanced Minikube Cluster Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that you have a Minikube cluster up and running, it's time to explore advanced features to gain a better understanding of Kubernetes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Updating Minikube&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To update Minikube to the latest version, use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;minikube update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deleting a Cluster&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you're finished with a Minikube cluster, you can delete it with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;minikube delete
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Managing Kubernetes Resources&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kubectl provides full management of Kubernetes resources. Here are some common operations:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a Deployment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can create a deployment with the following command, for example, for an application named "myapp":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl create deployment myapp &lt;span class="nt"&gt;--image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;my_image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Scaling an Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can adjust the number of replicas in a deployment to scale your application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl scale deployment/myapp &lt;span class="nt"&gt;--replicas&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Exposing a Service&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To expose a service, use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl expose deployment/myapp &lt;span class="nt"&gt;--type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;LoadBalancer &lt;span class="nt"&gt;--port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;80 &lt;span class="nt"&gt;--target-port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deploying and Updating Applications&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kubectl simplifies the deployment and updating of applications. You can deploy new versions of your applications without downtime using deployments. For example, to update the image of a running application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nb"&gt;set &lt;/span&gt;image deployment/myapp &lt;span class="nv"&gt;myapp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;my_image:v2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--az8mhStQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9u7hqsiw8vw2ynsqq9dj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--az8mhStQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9u7hqsiw8vw2ynsqq9dj.jpg" alt="Image description" width="540" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With Minikube and Kubectl, you now have the tools you need to explore Kubernetes on your own machine. Kubernetes is a powerful technology for container management and application orchestration. Explore its advanced features, test various scenarios, and develop your skills to master this powerful orchestrator.&lt;/p&gt;

&lt;p&gt;We hope this installation and usage guide for Minikube and Kubectl has provided you with a solid foundation to begin your journey into the world of Kubernetes. Feel free to explore further, experiment, and create increasingly complex applications to discover everything Kubernetes has to offer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n4jjj_Ql--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mryl540pv9r9w4aa9mb4.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n4jjj_Ql--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mryl540pv9r9w4aa9mb4.jpeg" alt="Image description" width="800" height="598"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://kubernetes.io/"&gt;Official Kubernetes Website&lt;/a&gt;: The official Kubernetes website is an essential resource, offering guides, documentation, tutorials, and more.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://minikube.sigs.k8s.io/docs/"&gt;Minikube Documentation&lt;/a&gt;: The official Minikube documentation is an excellent starting point to learn more about this tool.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://kubernetes.io/docs/reference/kubectl/overview/"&gt;Kubectl Documentation&lt;/a&gt;: The official Kubectl documentation provides detailed information on using this tool to interact with Kubernetes clusters.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/kelseyhightower/kubernetes-the-hard-way"&gt;Kubernetes the Hard Way&lt;/a&gt;: This training guide by Kelsey Hightower teaches you how to create a Kubernetes cluster from scratch for an in-depth understanding of Kubernetes.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.oreilly.com/library/view/kubernetes-up-and/9781492046530/"&gt;Kubernetes Up and Running&lt;/a&gt;: This book by Kelsey Hightower, Brendan Burns, and Joe Beda is ideal for those seeking a detailed introduction to Kubernetes.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://kubernetespodcast.com/"&gt;Kubernetes Podcast&lt;/a&gt;: The Kubernetes podcast is an excellent resource to stay up to date with the latest news, best practices, and success stories related to Kubernetes.&lt;/li&gt;
&lt;li&gt;Online Courses: Many platforms offer online courses on Kubernetes, such as Coursera, edX, Udemy, and Pluralsight, allowing you to learn at your own pace.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://stackoverflow.com/questions/tagged/kubernetes"&gt;Kubernetes Stack Overflow&lt;/a&gt; and &lt;a href="https://www.reddit.com/r/kubernetes/"&gt;Reddit&lt;/a&gt;: Join forums like Stack Overflow and Reddit groups dedicated to Kubernetes to ask questions, share experiences, and learn from others.&lt;/li&gt;
&lt;li&gt;Technical Blogs: Many experts share their knowledge of Kubernetes through technical blogs. Look for blogs by individuals like Kelsey Hightower, Brendan Burns, and others.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/kubernetes"&gt;GitHub&lt;/a&gt;: Explore open-source projects related to Kubernetes on GitHub to discover tools, scripts, and code examples.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These resources should help you deepen your knowledge of Kubernetes, Minikube, and Kubectl, whether you are a beginner or interested in exploring more advanced topics.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>kubect</category>
      <category>minikub</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
