<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ ansible - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ ansible - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 19 May 2026 04:43:51 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/ansible/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ What is Ansible? A Tool to Automate Parts of Your Job ]]>
                </title>
                <description>
                    <![CDATA[ Hello everyone, today we will talk about Ansible, a fantastic software tool that allows you to automate cross-platform computer support in a simple but effective way. Table of Contents What is Ansible? How Does Ansible Work? Ansible's Architecture P... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-ansible/</link>
                <guid isPermaLink="false">66b905e0472b70138041a589</guid>
                
                    <category>
                        <![CDATA[ ansible ]]>
                    </category>
                
                    <category>
                        <![CDATA[ automation ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Idris Olubisi ]]>
                </dc:creator>
                <pubDate>Fri, 29 Oct 2021 20:42:16 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/09/ansble.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hello everyone, today we will talk about Ansible, a fantastic software tool that allows you to automate cross-platform computer support in a simple but effective way.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li>What is Ansible?</li>
<li>How Does Ansible Work?</li>
<li>Ansible's Architecture<ul>
<li>Plugins</li>
<li>Modules</li>
<li>Inventories</li>
<li>Playbook</li>
</ul>
</li>
<li>Benefits of Using Ansible</li>
<li>Why is Ansible so important?</li>
<li>How to Install and Configure Ansible on Ubuntu</li>
<li>Conclusion</li>
<li>References</li>
</ul>
<h2 id="heading-what-is-ansible">What is Ansible?</h2>
<p>Ansible is a tool that generates written instructions for automating IT professionals' work throughout the entire system infrastructure.</p>
<p>It's designed particularly for IT professionals who use it for application deployment, configuration management, intra-service orchestration, and practically anything else a systems administrator does on a weekly or daily basis. </p>
<p>Ansible is simple to install because it doesn't require any agent software or other security infrastructure.</p>
<p>While Ansible is at the cutting edge of automation, systems administration, and DevOps, it's also valuable as a tool for devs to use in their daily work. </p>
<p>Ansible allows you to set up not just one machine but a complete network of them all at once, and it doesn't require any programming knowledge.</p>
<h2 id="heading-how-does-ansible-work">How Does Ansible Work?</h2>
<p>Ansible connects to nodes on a network (clients, servers, etc.) and then send a little program called an Ansible module to each node. </p>
<p>It then runs these modules through SSH and deletes them once they're done. </p>
<p>Your Ansible control node must have login access to the managed nodes for this interaction to work. </p>
<p>The most frequent method of authentication is SSH keys, but alternative methods are also allowed.</p>
<p>If you want to see how to install and start using Ansible, we'll cover that below.</p>
<h2 id="heading-ansibles-architecture">Ansible's Architecture</h2>
<p>Now let's take a look at Ansible's architecture and how it manages operations.</p>
<h3 id="heading-ansible-plugins">Ansible Plugins</h3>
<p>Plugins are supplementary pieces of code that enhance functionality, and you've probably used them in many other tools and platforms. You can use Ansible's built-in plugins or create your own. </p>
<p>Examples are: </p>
<ul>
<li>Action Plugins</li>
<li>Become Plugins</li>
<li>Cache Plugins</li>
<li>Callback Plugins</li>
<li>Cliconf Plugins</li>
<li>Connection Plugins</li>
<li>HTTP API Plugins</li>
<li>Inventory Plugins</li>
<li>Lookup Plugins</li>
<li>Netconf Plugins</li>
<li>Tests</li>
</ul>
<h3 id="heading-ansible-modules">Ansible Modules</h3>
<p>Modules are short programs that Ansible distributes to all nodes or remote hosts from a central control workstation. Modules control things like services and packages and can be executed via playbooks. </p>
<p>Ansible runs all of the modules needed to install updates or complete whatever operation is required and then removes them after they're done.</p>
<h3 id="heading-ansible-inventories">Ansible Inventories</h3>
<p>Ansible uses an inventory file to track which hosts are part of your infrastructure and then accesses them to perform commands and playbooks.</p>
<p>Ansible works in parallel with various systems in your infrastructure. It accomplishes this by picking methods mentioned in Ansible's inventory file, which is saved in the host location by default.</p>
<p>Once the inventory is registered, you can use a simple text file to assign variables to any of the hosts, and you may retrieve inventory from a variety of sources. </p>
<h3 id="heading-ansible-playbook">Ansible Playbook</h3>
<p>IT professionals can use Ansible playbooks to program applications, services, server nodes, and other devices without starting from scratch. Ansible playbooks, along with the conditions, variables, and tasks included within them, can be stored, shared, and reused forever.</p>
<p>Ansible playbooks function similarly to task manuals. They're simple <a target="_blank" href="https://en.wikipedia.org/wiki/YAML">YAML</a> files, a human-readable data serialization language. </p>
<p>Playbooks are at the heart of what makes Ansible so popular. They specify activities that can be completed quickly without requiring the user to know or remember any specific syntax.</p>
<h2 id="heading-benefits-of-using-ansible">Benefits of Using Ansible</h2>
<ul>
<li>Ansible is quick and easy to use, as it runs all of its operations over SSH and doesn't require the installation of any agents.</li>
<li>Ansible is a free, open-source tool, and it's straightforward to set up and use: Ansible's playbooks don't require any special coding knowledge.</li>
<li>Ansible can be used to perform simple tasks such as ensuring that a service is operating or rebooting from the command line without the need for configuration files.</li>
</ul>
<p>In a more extensive or more uniform system, Ansible may be a better fit. It also provides a set of modules for managing various methods and cloud infrastructure.</p>
<h2 id="heading-why-is-ansible-so-important">Why is Ansible so important?</h2>
<p>Modernization and digital transformation require automation that's both necessary and purposeful. We need a new management solution in today's dynamic contexts to increase speed, scale, and stability throughout IT infrastructure.</p>
<p>Technology is our most potent instrument for product improvement. Previously, accomplishing this required a significant amount of manual labor and intricate coordination. But today, Ansible - a simple yet powerful IT automation engine used by thousands of enterprises to simplify their setups and speed DevOps operations - is available.</p>
<h2 id="heading-how-to-install-ansible-on-ubuntu">How to Install Ansible on Ubuntu</h2>
<p>Run the following commands to configure the PPA on your machine and install Ansible:</p>
<p>Update the repository:</p>
<pre><code>sudo apt-get update
</code></pre><p>Install the software properties:</p>
<pre><code>sudo apt-get install software-properties-common
</code></pre><p>And then install Ansible like this:</p>
<pre><code>sudo apt-add-repository --yes --update ppa:ansible/ansible
</code></pre><p>Then run this:</p>
<pre><code>sudo apt-get install ansible
</code></pre><p>You should have something similar to what is shown below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/ansible_installation.png" alt="ansible_installation" width="600" height="400" loading="lazy"></p>
<p>Now that you have successfully installed Ansible, let's test if it's working by using the command below:</p>
<pre><code>ansible --version
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2021/10/ansible_check.png" alt="ansible_check" width="600" height="400" loading="lazy"></p>
<p>We'll use the command below to instruct Ansible to target all systems for the inventory host localhost, and we'll run the module ping from your local console (rather than ssh).</p>
<pre><code>ansible all -i localhost, --connection=local -m ping
</code></pre><p>You should get a response similar to what you can see below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/ansible_ping.png" alt="ansible_ping" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-modify-the-hosts-that-ansible-targets">How to modify the hosts that Ansible targets</h3>
<p>We'll make changes to the host's file in <code>/etc/ansible/hosts</code>. This is the default file where Ansible searches for any defined hosts (and groups) where the given commands should be executed remotely.</p>
<pre><code>sudo nano /etc/ansible/hosts
</code></pre><p>Add the lines below to the file and save the modifications:</p>
<pre><code>[local]
localhost
</code></pre><p>Execute this command with your adjusted inventory file:</p>
<pre><code>ansible all --connection=local -m ping
</code></pre><p>The response should look similar to what we have below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/ansible_pong.png" alt="ansible_pong" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-configure-a-remote-server">How to configure a remote server</h3>
<p>We deploy our Ansible test program to our remote server using a Digital Ocean droplet.</p>
<p>Use the command below to ssh into the server:</p>
<pre><code>ssh username@IP_Address
</code></pre><blockquote>
<p>Note: we have already configured an ssh key in our profile, which was selected when creating the droplet.</p>
</blockquote>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/ansible_server.png" alt="ansible_server" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-configure-ansible-for-a-remote-server">How to configure Ansible for a remote server</h3>
<p>We will edit our hosts file in /etc/ansible/hosts using the command below:</p>
<pre><code>sudo nano /etc/ansible/hosts
</code></pre><p>Add the lines below to the file and save the modifications:</p>
<pre><code>[remote]
remote_test

[remote:vars]
ansible_host=IP_ADDRESS_OF_VIRTUAL_MACHINE
ansible_user=USERNAME
</code></pre><p>To see if Ansible can connect to your remote compute instance over SSH, let's type the following command:</p>
<pre><code>ansible remote -m ping
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2021/10/asnible_result.png" alt="asnible_result" width="600" height="400" loading="lazy"></p>
<p>We'll make an Ansible playbook using the command below, which is the typical way of telling Ansible which commands to run on the remote server and in what order. The playbook is written in .yml and follows a strict format. </p>
<p>In the official <a target="_blank" href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html">Ansible documentation</a>, you can learn more about playbooks.</p>
<pre><code>nano my-playbook.yml
</code></pre><p>Add the following code, which tells Ansible to install Docker in several steps:</p>
<pre><code>---
- name: install docker
<span class="hljs-attr">hosts</span>: remote
<span class="hljs-attr">become_method</span>: sudo
<span class="hljs-attr">become_user</span>: root
<span class="hljs-attr">vars</span>: #local variables
<span class="hljs-attr">docker_packages</span>:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common

<span class="hljs-attr">tasks</span>:
- name: Update apt packages
<span class="hljs-attr">become</span>: <span class="hljs-literal">true</span> #make sure you execute the task <span class="hljs-keyword">with</span> sudo privileges
<span class="hljs-attr">apt</span>: #use apt <span class="hljs-built_in">module</span>
<span class="hljs-attr">update_cache</span>: yes #equivalent <span class="hljs-keyword">of</span> apt-get update

- name: Install packages needed <span class="hljs-keyword">for</span> Docker
<span class="hljs-attr">become</span>: <span class="hljs-literal">true</span>
<span class="hljs-attr">apt</span>:
name: <span class="hljs-string">"{{ docker_packages }}"</span> #uses our declared variable docker_packages
<span class="hljs-attr">state</span>: present #indicates the desired package state
<span class="hljs-attr">force_apt_get</span>: yes #forces to use apt-get

- name: Add official GPG key <span class="hljs-keyword">of</span> Docker
<span class="hljs-attr">shell</span>: curl -fsSL https:<span class="hljs-comment">//download.docker.com/linux/ubuntu/gpg | sudo apt-key add -</span>

- name: Save the current Ubuntu release version into a variable
<span class="hljs-attr">shell</span>: lsb_release -cs
<span class="hljs-attr">register</span>: ubuntu_version #Output gets stored <span class="hljs-keyword">in</span> <span class="hljs-built_in">this</span> variable

- name: <span class="hljs-built_in">Set</span> right Docker directory
<span class="hljs-attr">become</span>: <span class="hljs-literal">true</span>
<span class="hljs-attr">shell</span>: add-apt-repository <span class="hljs-string">"deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ubuntu_version.stdout }} stable"</span>

- name: Update apt packages
<span class="hljs-attr">become</span>: <span class="hljs-literal">true</span>
<span class="hljs-attr">apt</span>:
update_cache: yes

- name: Install Docker
<span class="hljs-attr">become</span>: <span class="hljs-literal">true</span>
<span class="hljs-attr">apt</span>:
name: docker-ce
<span class="hljs-attr">state</span>: present
<span class="hljs-attr">force_apt_get</span>: yes

- name: Test Docker <span class="hljs-keyword">with</span> hello world example
<span class="hljs-attr">become</span>: <span class="hljs-literal">true</span>
<span class="hljs-attr">shell</span>: docker run hello-world
<span class="hljs-attr">register</span>: hello_world_output

- name: Show output <span class="hljs-keyword">of</span> hello word example
<span class="hljs-attr">debug</span>: #use debug <span class="hljs-built_in">module</span>
<span class="hljs-attr">msg</span>: <span class="hljs-string">"Container Output: {{hello_world_output.stdout}}"</span>
</code></pre><p>We can now execute it with the command below:</p>
<pre><code>ansible-playbook my-playbook.yml -l remote
</code></pre><p>After that, we'll see some magic happen (it might take a while), and somewhere in the last debug message in our terminal, we should see "Hello from Docker!"</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, we had a detailed look into Ansible, its benefits, how it works and what it can do, its architecture, plugins, playbook, inventory, and how to configure and deploy Docker with Ansible on a remote server.</p>
<p>Thank you for reading!</p>
<h2 id="heading-resources">Resources</h2>
<p><a target="_blank" href="https://docs.ansible.com/">Ansible docs</a>
<a target="_blank" href="https://www.digitalocean.com/community/tutorials/how-to-set-up-ansible-inventories">Setting up Ansible Inventories</a>
<a target="_blank" href="https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html">Ansible installation</a></p>
<p>I'd love to connect with you on <a target="_blank" href="https://twitter.com/olanetsoft">Twitter</a> | <a target="_blank" href="https://www.linkedin.com/in/olubisi-idris-ayinde-05727b17a/">LinkedIn</a> | <a target="_blank" href="https://github.com/Olanetsoft">GitHub</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Ansible to Manage Your AWS Resources ]]>
                </title>
                <description>
                    <![CDATA[ Wouldn't you love to be able to simply wave a wand and layers of resources in your AWS account would suddenly - and magically - spring to perfectly configured life, ready to meet your complex infrastructure needs?  If you already have experience with... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/ansible-manage-aws/</link>
                <guid isPermaLink="false">66b995a4c39234149cf010f2</guid>
                
                    <category>
                        <![CDATA[ ansible ]]>
                    </category>
                
                    <category>
                        <![CDATA[ AWS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Orchestration ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ David Clinton ]]>
                </dc:creator>
                <pubDate>Mon, 28 Oct 2019 13:30:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/10/jean_victor_balin_icon_monitoring-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Wouldn't you love to be able to simply wave a wand and layers of resources in your AWS account would suddenly - and magically - spring to perfectly configured life, ready to meet your complex infrastructure needs? </p>
<p>If you already have experience with AWS, then you know how much of a pain it can be to work through web page after web page in the Amazon management console as you manually provision services. And even the AWS CLI - which is a huge step up - can add its own complexity and effort to the mix.</p>
<p>That's not to say that AWS itself doesn't address the problem with their own class of powerful orchestration tools, including CloudFormation and their Elastic Kubernetes Service (something I address at length in <a target="_blank" href="https://pluralsight.pxf.io/nZgKx">my "Using Docker on AWS" course at Pluralsight</a>). But neither of those options lives quite so close to your existing infrastructure - or uses as familiar a way of operating - as Ansible. </p>
<p>If you're already using Ansible for your on-premises operations, plugging it into your AWS account can sometimes be the quickest and most painless way to migrate operations to the cloud.</p>
<h3 id="heading-understanding-the-ansibleaws-advantage">Understanding the Ansible/AWS Advantage</h3>
<p>My book "<a target="_blank" href="https://www.amazon.com/gp/product/B07YK42ZH1/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B07YK42ZH1&amp;linkCode=as2&amp;tag=projemun-20&amp;linkId=d90b5a553223444f00992afa4c8f8d16">Manage AWS Resources Using Ansible</a>" - from which this article is excerpted - is designed to quickly introduce you to applying Ansible's <em>declarative</em> approach to working with AWS resources. Being able to "declare" the precise configuration results you want and then produce them by getting Ansible to read a playbook is Ansible's magic wand. When properly planned, it's amazing how simple it can be to execute complex, layered AWS deployments.</p>
<p>Before we launch a simple "Hello World" Ansible playbook, let's first make sure you've got a properly-configured working environment through which Ansible can communicate with all its new friends in your AWS account.</p>
<h3 id="heading-preparing-a-local-environment">Preparing a Local Environment</h3>
<p>As you probably already know, Ansible is an orchestration tool that lets you write plain-text <em>playbook</em> files that <em>declare</em> the software profile and ideal state you'd like applied to a target server. Those servers - known as hosts - can be provisioned for just about any digital workload you can imagine, using just about any combination of application software, and running on just about any platform.</p>
<p>In the good old days, when a playbook was run against a physical server, Ansible would employ an existing SSH connection to securely login to the remote host and go about building your application. But that won't work for AWS workloads. You see, because the EC2 instances and other infrastructure you want to launch don't yet exist, there can be no "existing" SSH connections. Instead, Ansible will use Boto 3 - the software development kit (or SDK) used by AWS that allows Python code to communicate with the AWS API.</p>
<h3 id="heading-using-the-aws-cli-to-connect-ansible">Using the AWS CLI to Connect Ansible</h3>
<p>You don't have to know how all that works, but it has to be there so it <em>can</em> work. For that reason you're going to install the AWS command line interface (CLI). We won't be using the CLI itself for anything important, but installing it will give us all the dependencies we'll need. You can find out how to make this work on the latest version of whatever OS you're using from the <a target="_blank" href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html">AWS documentation page</a>.</p>
<p>Working with the Python package manager, PIP, is a popular way to get all this done. Here's how you would install PIP itself and then the AWS CLI on an Ubuntu machine:</p>
<pre><code>sudo apt update
sudo apt install python3-pip
pip3 install awscli
</code></pre><p>I should note that, as I write this, Python 2 is still alive...but only just. So there might sometimes still be separate Python 2 and Python 3 versions installed on your system. Since Python 2 will soon be fully deprecated, you probably won't have to worry about specifying python3 or pip3 with your commands: that should be automatic.</p>
<p>Once the CLI is installed, run <code>aws configure</code> and enter your AWS access key ID and secret access key.</p>
<pre><code>aws configure
cat .aws/credentials
</code></pre><p>You can get keys from the Your Security Credentials page in the AWS Management Console. Here's how those keys will look (don't get any naughty ideas, these aren't valid):</p>
<pre><code>AccessKeyId: AKIALNZTQW6H3EFBRLHQ
<span class="hljs-attr">SecretAccessKey</span>: f26B8touguUBELGpdyCyc9o0ZDzP2MEUWNC0JNwA
</code></pre><p>Just remember that a pair of keys issued to the root user of your AWS account provides full access to your entire AWS account. Anyone in possession of those credentials would be quickly able to run up six and even seven figure services charges, so be <em>very</em> careful how you use and store them. Ideally, you would be better off limiting your risk exposure by creating an admin user in the AWS Identify and Access Management (IAM) service with limited powers and using a key issued to that user.</p>
<p>At any rate, why am I doing this? The value of populating my AWS credentials file is that Ansible is smart enough to look for it and, if no other authentication keys are available in the system environment, it'll use these. You'll soon see how mighty convenient that will be. However, you should be aware of other ways to manage authentication for Ansible playbooks, like using <em>ansible-vault</em> or by creating and then invoking an aws_keys.yml file. But one thing you should definitely NOT do is hardcode the keys in your playbook files - especially if you plan to push them to an online repository like GitHub. I'll quickly test the CLI to make sure we can properly connect to AWS. This simple command will list any S3 buckets I happen to have within this account.</p>
<pre><code>aws s3 ls
</code></pre><p>We're now ready to install ansible. I'll go with pip3 for that. I could use the regular Ubuntu apt repository just as easily, but it will most likely install a slightly older version. Depending on your network connection, that'll take a minute or two, but I'll skip most of that.</p>
<pre><code>$ pip3 install ansible
</code></pre><p>I'll confirm that it's properly installed by running ansible --version. This shows us the version that was built, that configured Ansible modules will, by default, be saved in either one of these two locations in the file system, that other modules would be available here and - most importantly - that the Ansible executable is located within the /local/bin/ directory beneath my user's home directory. My user here, by the way, is called ubuntu. You can also see that we're using a nice, up-to-date version of Python 3.</p>
<pre><code>$ ansible --version
ansible <span class="hljs-number">2.8</span><span class="hljs-number">.5</span>
  config file = None
  configured <span class="hljs-built_in">module</span> search path = 
    [<span class="hljs-string">'/home/ubuntu/.ansible/plugins/modules'</span>, 
    <span class="hljs-string">'/usr/share/ansible/plugins/modules'</span>]
  ansible python <span class="hljs-built_in">module</span> location = 
    <span class="hljs-regexp">/home/u</span>buntu/.local/lib/python3<span class="hljs-number">.6</span>/site-packages/ansible
  executable location = <span class="hljs-regexp">/home/u</span>buntu/.local/bin/ansible
  python version = <span class="hljs-number">3.6</span><span class="hljs-number">.8</span> (<span class="hljs-keyword">default</span>, Aug <span class="hljs-number">20</span> <span class="hljs-number">2019</span>, <span class="hljs-number">17</span>:<span class="hljs-number">12</span>:<span class="hljs-number">48</span>) [GCC <span class="hljs-number">8.3</span><span class="hljs-number">.0</span>]
</code></pre><p>One more step. As I mentioned earlier, Ansible will connect to AWS using the boto SDK. So we'll need to install the boto and boto 3 packages. I'll go with PIP for this one, too.</p>
<pre><code>$ pip3 install boto boto3
</code></pre><p>Once that one has been brought on board, we'll be ready to get some real stuff done. That'll begin in the next section.</p>
<h2 id="heading-testing-ansible-with-a-simple-playbook">Testing Ansible with a Simple Playbook</h2>
<p>This is going to be very simple proof of concept demo. I'll create a couple of files, walk you through the syntax, and then fire it up. First off, I'll use any plain text editor to create a <em>hosts</em> file. Normally, the hosts file tells Ansible where it can find the remote servers you want to provision. But since, in the case of AWS, the resources that will be our hosts don't yet exist, we'll simply point Ansible to localhost and boto will handle connections behind the scenes. Here's what the contents of that file will look like:</p>
<pre><code>[local]
localhost
</code></pre><p>Next, I'll create a playbook file that I'll call test-ansible.yml. The yml extension, of course, indicates that this file must be formatted using YAML markup language syntax. As you can see from the file text I've pasted just below, that'll begin with three dashes marking the start of the file and then an indented dash introducing a set of definitions. The value of "hosts" could be one or more remote computers but, as I've said, we'll leave that up to the local system to figure out. The same goes for our connection.</p>
<p>The next section includes the <em>tasks</em> we want Ansible to perform. This one will use the aws_s3 module to <em>create</em> a new bucket on Amazon's S3 Simple Storage Service in the us-east-1 region. I have to give it this ugly name because S3 buckets require globally unique names - if a name you choose clashes with any one of the countless millions of names already out there, the operation will fail.</p>
<pre><code class="lang-yaml"><span class="hljs-meta">---</span>
  <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Test</span> <span class="hljs-string">s3</span>
    <span class="hljs-attr">hosts:</span> <span class="hljs-string">local</span>
    <span class="hljs-attr">connection:</span> <span class="hljs-string">local</span>

    <span class="hljs-attr">tasks:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Create</span> <span class="hljs-string">new</span> <span class="hljs-string">bucket</span>
        <span class="hljs-attr">aws_s3:</span>
          <span class="hljs-attr">bucket:</span> <span class="hljs-string">testme817275b</span>
          <span class="hljs-attr">mode:</span> <span class="hljs-string">create</span>
          <span class="hljs-attr">region:</span> <span class="hljs-string">us-east-1</span>
</code></pre>
<p>I run the playbook by calling the ansible-playbook command using -i to specify the hosts file, and then pointing to the test.yml file. Ansible should give us some feedback in just a moment or two. If we're successful, you'll see "0" as the value of "failed" and at least "1" as the value of "ok".</p>
<pre><code>$ ansible-playbook -i hosts test-ansible.yml
PLAY [Test s3] ******************************************************

TASK [Create <span class="hljs-keyword">new</span> bucket] ********************************************

changed: [localhost]

PLAY RECAP **********************************************************
localhost: ok=<span class="hljs-number">1</span>    changed=<span class="hljs-number">1</span>    unreachable=<span class="hljs-number">0</span>    failed=<span class="hljs-number">0</span>   skipped=<span class="hljs-number">0</span>
    rescued=<span class="hljs-number">0</span>    ignored=<span class="hljs-number">0</span>
</code></pre><p>If I check my list of buckets once more, I should - and do - see the new one:</p>
<pre><code>$ aws s3 ls
<span class="hljs-number">2018</span><span class="hljs-number">-12</span><span class="hljs-number">-30</span> <span class="hljs-number">15</span>:<span class="hljs-number">19</span>:<span class="hljs-number">24</span> elasticbeanstalk-us-east<span class="hljs-number">-1</span><span class="hljs-number">-297972716276</span>
<span class="hljs-number">2018</span><span class="hljs-number">-10</span><span class="hljs-number">-12</span> <span class="hljs-number">04</span>:<span class="hljs-number">09</span>:<span class="hljs-number">37</span> mysite548.com
<span class="hljs-number">2019</span><span class="hljs-number">-09</span><span class="hljs-number">-24</span> <span class="hljs-number">15</span>:<span class="hljs-number">53</span>:<span class="hljs-number">26</span> testme817275b
</code></pre><p>That's a very brief intro to setting up an Ansible environment. We saw how using Ansible with Amazon's automatically provisioned resources is going to work differently than it would with traditional Ansible hosts. You're going to require a different set of authentication and inventory control tools. We walked through the process of setting up an Ansible environment and connecting it to AWS, and then running a simple playbook. Short and sweet.</p>
<p>This article comes from my book "<a target="_blank" href="https://www.amazon.com/gp/product/B07YK42ZH1/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B07YK42ZH1&amp;linkCode=as2&amp;tag=projemun-20&amp;linkId=d90b5a553223444f00992afa4c8f8d16">Manage AWS Resources Using Ansible</a>". There's more technology goodness - in the form of books, courses, and articles - available on my <a target="_blank" href="https://bootstrap-it.com">website, bootstrap-it.com</a>. </p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
