{"id":11231,"date":"2025-04-15T10:07:21","date_gmt":"2025-04-15T10:07:21","guid":{"rendered":"https:\/\/mainvps.net\/blog\/?p=11231"},"modified":"2025-05-19T11:16:04","modified_gmt":"2025-05-19T11:16:04","slug":"install-ansible-on-ubuntu","status":"publish","type":"post","link":"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/","title":{"rendered":"How to Install Ansible on Ubuntu 22.04 (Step-by-Step Guide)"},"content":{"rendered":"\n<p>Before we dive into the installation process of Ansible on Ubuntu, let\u2019s first explore what Ansible is, why it\u2019s beneficial to install ansible on Ubuntu, and the prerequisites you should know before getting started.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#What_is_Ansible\" >What is Ansible?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Why_Use_Ansible_on_Ubuntu\" >Why Use Ansible on Ubuntu?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Common_Use_Cases_for_Ansible\" >Common Use Cases for Ansible<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Prerequisites_Before_Installing_Ansible_on_Ubuntu\" >Prerequisites Before Installing Ansible on Ubuntu<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#What_You_Need_System_Requirements\" >What You Need (System Requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Update_and_Upgrade_Your_System\" >Update and Upgrade Your System<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Install_Required_Packages\" >Install Required Packages<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Method_1_%E2%80%93_Installing_Ansible_Using_Apt_Official_Ubuntu_Repos\" >Method 1 \u2013 Installing Ansible Using Apt (Official Ubuntu Repos)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Step-by-Step_Installation\" >Step-by-Step Installation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Pros_and_Cons_of_This_Method\" >Pros and Cons of This Method<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Method_2_%E2%80%93_Installing_Ansible_Using_PPA_Preferred_for_Latest_Version\" >Method 2 \u2013 Installing Ansible Using PPA (Preferred for Latest Version)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Add_Ansible_PPA\" >Add Ansible PPA<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Install_Latest_Ansible_Version\" >Install Latest Ansible Version<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Verify_the_Installation\" >Verify the Installation<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Method_3_%E2%80%93_Installing_Ansible_via_Pip_Python_Package_Manager\" >Method 3 \u2013 Installing Ansible via Pip (Python Package Manager)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#When_to_Use_pip_for_Ansible\" >When to Use pip for Ansible<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Installing_pip_and_Ansible\" >Installing pip and Ansible<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Pros_and_Cons_of_pip_Method\" >Pros and Cons of pip Method<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Post-Installation_Setup\" >Post-Installation Setup<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Creating_an_Ansible_Inventory_File\" >Creating an Ansible Inventory File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Setting_Up_SSH_Access_to_Managed_Nodes\" >Setting Up SSH Access to Managed Nodes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Running_Your_First_Ansible_Command\" >Running Your First Ansible Command<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Troubleshooting_Common_Ansible_Installation_Issues\" >Troubleshooting Common Ansible Installation Issues<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Fixing_Broken_Dependencies\" >Fixing Broken Dependencies<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Resolving_pip_Errors\" >Resolving pip Errors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Checking_Python_and_pip_Versions\" >Checking Python and pip Versions<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Best_Practices_for_Using_Ansible_on_Ubuntu\" >Best Practices for Using Ansible on Ubuntu<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Organizing_Your_Playbooks_and_Roles\" >Organizing Your Playbooks and Roles<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Using_Virtual_Environments\" >Using Virtual Environments<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Keeping_Ansible_Up_to_Date\" >Keeping Ansible Up to Date<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#FAQs\" >FAQs<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#1_What_is_the_default_location_of_Ansible_config_files\" >1. What is the default location of Ansible config files?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#2_Can_I_use_Ansible_without_root_access\" >2. Can I use Ansible without root access?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#3_Is_Ansible_agentless\" >3. Is Ansible agentless?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#4_Whats_the_difference_between_Ansible_and_Terraform\" >4. What\u2019s the difference between Ansible and Terraform?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-37\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/#5_How_do_I_upgrade_Ansible_on_Ubuntu\" >5. How do I upgrade Ansible on Ubuntu?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_Ansible\"><\/span><strong>What is Ansible?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Imagine having dozens of servers and needing to configure or update them all at once. Doing it manually? That\u2019d be a nightmare. <strong>Enter Ansible<\/strong> \u2014 an open-source, agentless automation tool that lets you manage systems, deploy apps, and orchestrate configurations with ease.<\/p>\n\n\n\n<p>Ansible uses <strong>YAML-based playbooks<\/strong> to define your automation tasks. It\u2019s simple, powerful, and \u2014 best of all \u2014 doesn\u2019t require installing any agent on the nodes you want to manage. You just need SSH access and Python installed.<\/p>\n\n\n\n<p>In short, it\u2019s like having a remote control for your infrastructure, and yes, it\u2019s as cool as it sounds.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_Use_Ansible_on_Ubuntu\"><\/span><strong>Why Use Ansible on Ubuntu?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Ubuntu is one of the most widely used <a href=\"https:\/\/mainvps.net\/linux-vps-hosting\">Linux distributions for servers<\/a> and dev environments, and pairing it with Ansible makes automation even smoother.<\/p>\n\n\n\n<p>Here\u2019s why Ansible + Ubuntu = match made in DevOps heaven:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ubuntu\u2019s package system makes installing Ansible painless<\/li>\n\n\n\n<li>Built-in Python support ensures compatibility<\/li>\n\n\n\n<li>Strong community support<\/li>\n\n\n\n<li>Ideal for cloud environments (AWS, Azure, DigitalOcean, etc.)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Common_Use_Cases_for_Ansible\"><\/span><strong>Common Use Cases for Ansible<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Provisioning cloud instances<\/li>\n\n\n\n<li>Patching and updating servers<\/li>\n\n\n\n<li>Automating repetitive tasks<\/li>\n\n\n\n<li>Managing Docker containers<\/li>\n\n\n\n<li>Deploying web servers or microservices<\/li>\n\n\n\n<li>Setting up dev environments for teams<\/li>\n<\/ul>\n\n\n\n<p>With Ansible, you write it once and reuse it forever. Total time-saver!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Prerequisites_Before_Installing_Ansible_on_Ubuntu\"><\/span><strong>Prerequisites Before Installing Ansible<\/strong> on Ubuntu<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_You_Need_System_Requirements\"><\/span><strong>What You Need (System Requirements<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To install Ansible on Ubuntu 22.04, you need:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A system running <strong>Ubuntu 22.04 LTS<\/strong><\/li>\n\n\n\n<li><strong>Sudo privileges<\/strong> or root access<\/li>\n\n\n\n<li>Internet connection to pull packages<\/li>\n\n\n\n<li>Basic terminal knowledge<\/li>\n<\/ul>\n\n\n\n<p>If you plan on managing other systems, make sure:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SSH is enabled on the target machines<\/li>\n\n\n\n<li>Python is installed (it\u2019s usually already there on most Linux distros)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Update_and_Upgrade_Your_System\"><\/span><strong>Update and Upgrade Your System<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Before installing anything new, it\u2019s always a good idea to make sure your system is up-to-date.<\/p>\n\n\n\n<p>Run:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bash<br>sudo apt update &amp;&amp; sudo apt upgrade -y<br><\/pre>\n\n\n\n<p>This ensures that you\u2019re not running into any conflicts during or after installation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Install_Required_Packages\"><\/span><strong>Install Required Packages<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Ansible relies on Python and a few supporting tools. Run this to install what you need:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bash<br>sudo apt install software-properties-common python3 python3-pip -y<\/pre>\n\n\n\n<p>These packages enable the addition of <a href=\"https:\/\/ubuntu.com\/landscape\/docs\/explanation-PPA\" target=\"_blank\" rel=\"noopener\">PPAs<\/a> and handle Python-based dependencies. Python is especially important since Ansible is written in Python and depends on it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Method_1_%E2%80%93_Installing_Ansible_Using_Apt_Official_Ubuntu_Repos\"><\/span><strong>Method 1 \u2013 Installing Ansible Using Apt (Official Ubuntu Repos)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-by-Step_Installation\"><\/span><strong>Step-by-Step Installation<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Ubuntu 22.04 includes Ansible in its default repositories. If you\u2019re okay with using the version that Ubuntu provides (which may not always be the latest), then this is the fastest and easiest way.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Install Ansible: <\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong><em>bash<\/em><\/strong><br><br>sudo apt install ansible -y<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check the installed version: <\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong><em>bash<\/em><\/strong><br><br><code>ansible --version<\/code> You should see something like: <br>css<br>ansible [core 2.10.x]<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>That\u2019s it! Ansible is now installed and ready to go.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Pros_and_Cons_of_This_Method\"><\/span><strong>Pros and Cons of This Method<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>Pros:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Quick and easy<\/li>\n\n\n\n<li>Stable packages from Ubuntu repos<\/li>\n\n\n\n<li>Minimal setup required<\/li>\n<\/ul>\n\n\n\n<p><strong>Cons:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Version may be outdated compared to upstream releases<\/li>\n\n\n\n<li>Some new features might be missing<\/li>\n<\/ul>\n\n\n\n<p>If you\u2019re just getting started or setting up a non-critical environment, this method is totally fine. But if you need the latest features, check out the next method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Method_2_%E2%80%93_Installing_Ansible_Using_PPA_Preferred_for_Latest_Version\"><\/span><strong>Method 2 \u2013 Installing Ansible Using PPA (Preferred for Latest Version)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Add_Ansible_PPA\"><\/span><strong>Add Ansible PPA<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Ansible provides its own official PPA (Personal Package Archive) with the latest version for Ubuntu systems. This is the recommended way to get the most current, stable release.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li style=\"font-size:18px\">Add the PPA: <br>bash<br><em>sudo add-apt-repository &#8211;yes &#8211;update ppa:ansible\/ansible<\/em><\/li>\n<\/ol>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Update package list: <\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong><em>bash<\/em><\/strong><br><br><em>sudo apt update<\/em><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Install_Latest_Ansible_Version\"><\/span><strong>Install Latest Ansible Version<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Now install Ansible from the PPA: bashCopyEdit<code>sudo apt install ansible -y<\/code><\/li>\n\n\n\n<li style=\"font-size:18px\">Confirm the version: <\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\"><strong><em>bash<br><\/em><\/strong><br><em>ansible --version You\u2019ll likely see something like: <br>css<br>ansible [core 2.14.x]<\/em><\/pre>\n\n\n\n<p>This version includes newer modules, improved playbook performance, and enhanced cloud integrations.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Verify_the_Installation\"><\/span><strong>Verify the Installation<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Try running a quick ping to localhost:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bash<br>ansible localhost -m ping --connection=local<\/pre>\n\n\n\n<p>If you get a <code>\"pong\"<\/code> response, you\u2019re officially up and running!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Method_3_%E2%80%93_Installing_Ansible_via_Pip_Python_Package_Manager\"><\/span><strong>Method 3 \u2013 Installing Ansible via Pip (Python Package Manager)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"When_to_Use_pip_for_Ansible\"><\/span><strong>When to Use pip for Ansible<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Using <code>pip<\/code> to install Ansible on ubuntu is ideal if:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You want to run multiple Ansible versions (per project)<\/li>\n\n\n\n<li>You&#8217;re using Python virtual environments<\/li>\n\n\n\n<li>You\u2019re building a custom setup or working in a Python-centric workflow<\/li>\n<\/ul>\n\n\n\n<p>This method gives you <strong>flexibility and control<\/strong>, especially if you\u2019re managing automation scripts in isolated environments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Installing_pip_and_Ansible\"><\/span><strong>Installing pip and Ansible<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If <code>pip<\/code> isn\u2019t already installed, start with:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\"><strong><em>bash<\/em><\/strong><br>sudo apt install python3-pip -y<\/pre>\n\n\n\n<p>Then, install Ansible using pip:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\"><strong><em>bash<\/em><\/strong><br>pip3 install --user ansible<\/pre>\n\n\n\n<p>This installs Ansible in your user directory without requiring <code>sudo<\/code>. To make sure it\u2019s accessible from your terminal, add the following to your <code>.bashrc<\/code> or <code>.zshrc<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\"><strong><em>bash<br><\/em><\/strong>export PATH=$PATH:~\/.local\/bin<\/pre>\n\n\n\n<p>Reload the shell or source the config:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\"><strong><em>bash<\/em><\/strong><br>source ~\/.bashrc<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Pros_and_Cons_of_pip_Method\"><\/span><strong>Pros and Cons of pip Method<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>Pros:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Installs the latest version directly from PyPI<\/li>\n\n\n\n<li>Works well with Python virtual environments<\/li>\n\n\n\n<li>Great for isolated, project-specific installations<\/li>\n<\/ul>\n\n\n\n<p><strong>Cons:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Slightly more manual setup<\/li>\n\n\n\n<li>Not managed through your system package manager<\/li>\n\n\n\n<li>Can cause confusion if multiple versions are installed<\/li>\n<\/ul>\n\n\n\n<p>Use this method if you&#8217;re comfortable with Python and want more fine-tuned control over your environment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Post-Installation_Setup\"><\/span><strong>Post-Installation Setup<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_an_Ansible_Inventory_File\"><\/span><strong>Creating an Ansible Inventory File<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The <strong>inventory file<\/strong> tells Ansible where your target machines live. By default, it&#8217;s located at:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\"><strong><em>bash<br><\/em><\/strong>\/etc\/ansible\/hosts<\/pre>\n\n\n\n<p>Here\u2019s a simple example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">ini<br>[webservers]<br>192.168.1.10<br>192.168.1.11<br><br>[databases]<br>192.168.1.12<\/pre>\n\n\n\n<p>This allows you to group hosts and target them in playbooks or ad-hoc commands.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Setting_Up_SSH_Access_to_Managed_Nodes\"><\/span><strong>Setting Up SSH Access to Managed Nodes<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Ansible connects to other machines via SSH. Make sure:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SSH is installed on both control and target machines<\/li>\n\n\n\n<li>You have passwordless SSH access (via keys)<\/li>\n<\/ul>\n\n\n\n<p>To generate an SSH key (if you don\u2019t have one already):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bash<br>ssh-keygen<\/pre>\n\n\n\n<p>Then copy your key to the target server:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bash<br>ssh-copy-id user@192.168.1.10<\/pre>\n\n\n\n<p>This step is crucial because Ansible is <strong>agentless<\/strong> \u2014 it relies on SSH instead of running a separate daemon on the managed nodes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Running_Your_First_Ansible_Command\"><\/span><strong>Running Your First Ansible Command<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>With SSH set up and your inventory ready, try this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bas<br>ansible all -m ping<\/pre>\n\n\n\n<p>If everything\u2019s working, each host will reply with <code>\"pong\"<\/code>. This confirms that Ansible can reach and communicate with your machines.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Troubleshooting_Common_Ansible_Installation_Issues\"><\/span><strong>Troubleshooting Common Ansible Installation Issues<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Fixing_Broken_Dependencies\"><\/span><strong>Fixing Broken Dependencies<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If Ansible won\u2019t install or throws dependency errors:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li style=\"font-size:18px\">Clean the package manager cache: <br>bash<br><em>sudo apt clean sudo apt update<\/em><\/li>\n\n\n\n<li style=\"font-size:18px\">Use <code>--fix-broken<\/code> to resolve missing dependencies: <br>bash<br><em>sudo apt &#8211;fix-broken install<\/em><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Resolving_pip_Errors\"><\/span><strong>Resolving pip Errors<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Common <code>pip<\/code>-related errors:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Permission denied<\/strong>: Use <code>--user<\/code> to install without sudo.<\/li>\n\n\n\n<li><strong>Path not found<\/strong>: Add<em> ~\/.local\/bin <\/em>to your <em>$PATH<\/em>.<\/li>\n<\/ul>\n\n\n\n<p>Example fix:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bash<br>echo 'export PATH=$PATH:~\/.local\/bin' &gt;&gt; ~\/.bashrc<br>source ~\/.bashrc<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Checking_Python_and_pip_Versions\"><\/span><strong>Checking Python and pip Versions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Make sure Python and pip are correctly installed:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bash<br>python3 --version<br>pip3 --version<\/pre>\n\n\n\n<p>Ansible needs Python 3.6+ to run smoothly. If your system doesn\u2019t meet the requirements, upgrade Python first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Best_Practices_for_Using_Ansible_on_Ubuntu\"><\/span><strong>Best Practices for Using Ansible on Ubuntu<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Organizing_Your_Playbooks_and_Roles\"><\/span><strong>Organizing Your Playbooks and Roles<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Once you&#8217;re comfortable running a few ad-hoc commands, it&#8217;s time to level up your Ansible game. Start organizing your automation using <strong>playbooks<\/strong> and <strong>roles<\/strong>.<\/p>\n\n\n\n<p>Structure your project like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">css<br>project\/<br>\u251c\u2500\u2500 inventory<br>\u251c\u2500\u2500 ansible.cfg<br>\u251c\u2500\u2500 playbook.yml<br>\u2514\u2500\u2500 roles\/<br>    \u251c\u2500\u2500 webserver\/<br>    \u2502   \u251c\u2500\u2500 tasks\/<br>    \u2502   \u2502   \u2514\u2500\u2500 main.yml<br>    \u2502   \u251c\u2500\u2500 handlers\/<br>    \u2502   \u2514\u2500\u2500 templates\/<br>    \u2514\u2500\u2500 database\/<code><br><\/code><\/pre>\n\n\n\n<p>Why use this structure?<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Makes your setup scalable and reusable<\/li>\n\n\n\n<li>Helps you collaborate with teams more easily<\/li>\n\n\n\n<li>Keeps things tidy and easy to troubleshoot<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_Virtual_Environments\"><\/span><strong>Using Virtual Environments<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>For Python users or teams managing multiple projects, using virtual environments is a smart move:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bash<br>python3 -m venv ansible-env<br>source ansible-env\/bin\/activate<br>pip install ansible<\/pre>\n\n\n\n<p>This way, your Ansible version is isolated from the system version \u2014 perfect for avoiding conflicts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Keeping_Ansible_Up_to_Date\"><\/span><strong>Keeping Ansible Up to Date<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If you installed Ansible using <code>apt<\/code> or the official PPA, update it regularly:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bash<br>sudo apt update<br>sudo apt upgrade ansible<\/pre>\n\n\n\n<p>If you used <code>pip<\/code>, then:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bash<br>pip install --upgrade ansible<\/pre>\n\n\n\n<p>Staying updated ensures you get:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>New modules and features<\/li>\n\n\n\n<li>Performance enhancements<\/li>\n\n\n\n<li>Security patches<\/li>\n<\/ul>\n\n\n\n<p>Always check Ansible\u2019s <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/reference_appendices\/release_and_maintenance.html\" target=\"_blank\" rel=\"noopener\">release notes<\/a> for major version changes before upgrading in production.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The install of&nbsp;<strong>Ansible on Ubuntu 22.04<\/strong> process&nbsp;is fast, easy, simple, and user-friendly, no matter if you&#8217;re an experienced DevOps professional or just beginning your journey to automation.<\/p>\n\n\n\n<p>You\u2019ve now learned:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>How to install Ansible on ubuntu using <code>apt<\/code>, PPA, and <code>pip<\/code><\/li>\n\n\n\n<li>How to configure your inventory and test SSH access<\/li>\n\n\n\n<li>The basics of running Ansible commands<\/li>\n\n\n\n<li>How to troubleshoot and apply best practices<\/li>\n<\/ul>\n\n\n\n<p>With Ansible within your toolbox You&#8217;re not just managing servers &#8211; you can master the process.&nbsp;Automatization is the way of the future and Ansible assists you in achieving it with less stress and more power available to you.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQs\"><\/span><strong>FAQs<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_What_is_the_default_location_of_Ansible_config_files\"><\/span><strong>1. What is the default location of Ansible config files?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The default config file is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\" style=\"font-size:18px\">bash<br>\/etc\/ansible\/ansible.cfg<\/pre>\n\n\n\n<p>You can create a project-specific config file in your working directory for custom settings like inventory paths and logging.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Can_I_use_Ansible_without_root_access\"><\/span><strong>2. Can I use Ansible without root access?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Yes, but you\u2019ll need:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SSH access to the target machines<\/li>\n\n\n\n<li>Sudo permissions configured for the user (if you need to make privileged changes)<\/li>\n<\/ul>\n\n\n\n<p>You can also configure Ansible to use <code>--ask-become-pass<\/code> for privilege escalation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Is_Ansible_agentless\"><\/span><strong>3. Is Ansible agentless?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Absolutely. That\u2019s one of its biggest perks. It doesn\u2019t need to install anything on the nodes it manages \u2014 just <a href=\"https:\/\/mainvps.net\/blog\/enable-or-disable-password-authentication-in-ssh\/\">SSH access<\/a> and Python (usually already there on Linux systems).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Whats_the_difference_between_Ansible_and_Terraform\"><\/span><strong>4. What\u2019s the difference between Ansible and Terraform?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Ansible<\/strong>: Focuses on configuration management and automation after infrastructure exists.<\/li>\n\n\n\n<li><strong>Terraform<\/strong>: Focuses on <strong>infrastructure provisioning<\/strong> \u2014 setting up servers, databases, and networks.<\/li>\n<\/ul>\n\n\n\n<p>Many teams use both tools together in DevOps pipelines.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_How_do_I_upgrade_Ansible_on_Ubuntu\"><\/span><strong>5. How do I upgrade Ansible on Ubuntu?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>It depends on how you installed it:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li style=\"font-size:18px\"><strong>From apt<\/strong>: <br>bash<br><em>sudo apt update &amp;&amp; sudo apt upgrade ansible<\/em><\/li>\n\n\n\n<li style=\"font-size:18px\"><strong>From pip<\/strong>: bash<br><em>pip install &#8211;upgrade ansible<\/em><\/li>\n\n\n\n<li style=\"font-size:18px\"><strong>From PPA<\/strong>: Update the PPA and install the new version: <br>bash<br><em>sudo apt update sudo apt upgrade<\/em><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Before we dive into the installation process of Ansible on Ubuntu, let\u2019s first explore what Ansible is, why it\u2019s beneficial to install ansible on Ubuntu, and <a class=\"read-more-link\" href=\"https:\/\/mainvps.net\/blog\/install-ansible-on-ubuntu\/\">Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":11487,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-11231","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-hosting"],"_links":{"self":[{"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/posts\/11231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/comments?post=11231"}],"version-history":[{"count":6,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/posts\/11231\/revisions"}],"predecessor-version":[{"id":11482,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/posts\/11231\/revisions\/11482"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/media\/11487"}],"wp:attachment":[{"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/media?parent=11231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/categories?post=11231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/tags?post=11231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}