<?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:foaf="http://xmlns.com/foaf/0.1/" xmlns:og="http://ogp.me/ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:schema="http://schema.org/" xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:sioct="http://rdfs.org/sioc/types#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" version="2.0" xml:base="https://www.linuxjournal.com/">
  <channel>
    <title>Ansible</title>
    <link>https://www.linuxjournal.com/</link>
    <description/>
    <language>en</language>
    
    <item>
  <title>How to Create EC2 Duplicate Instance with Ansible</title>
  <link>https://www.linuxjournal.com/content/how-to-create-ec2-duplicate-instance-ansible</link>
  <description>  &lt;div data-history-node-id="1340807" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/tomasz-szandala" lang="" about="https://www.linuxjournal.com/users/tomasz-szandala" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Tomasz Szandała&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;Many companies like mine use AWS infrastructure as a service (IaaS) heavily. Sometimes we want to perform a potentially risky operation on an EC2 instance. As long as we do not work with immutable infrastructure it is imperative to be prepared for instant revert.&lt;/p&gt;

&lt;p&gt;One of the solutions is to use a script that will perform instance duplication, but in modern environments, where unification is an essence it would be wiser to use more common known software instead of making up a custom script.&lt;/p&gt;

&lt;p&gt;Here comes the Ansible!&lt;/p&gt;

&lt;p&gt;Ansible is a simple automation software. It handles configuration management, application deployment, cloud provisioning, ad-hoc task execution, network automation, and multi-node orchestration. It is marketed as a tool for making complex changes like zero-downtime rolling patching, therefore we have used it for this straightforward snapshotting task.&lt;/p&gt;

&lt;h2&gt;Requirements&lt;/h2&gt;

&lt;p&gt;For this example we will only need an Ansible, in my case it was version 2.9 - in subsequent releases there is a major change with introducing collections so let's stick with this one for simplicity.&lt;/p&gt;

&lt;p&gt;Due to working with AWS we require a minimal set of permissions, which include permissions to create:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;AWS snapshots&lt;/li&gt;
	&lt;li&gt;Register images (AMI)&lt;/li&gt;
	&lt;li&gt;Start and stop EC2&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;Environment preparation&lt;/h2&gt;

&lt;p&gt;Since I am forced to work on Windows I have utilized Vagrant instances. Please find below a Vagrantfile content.&lt;/p&gt;

&lt;p&gt;We are launching a virtual machine, with Centos 7 and Ansible installed.&lt;/p&gt;

&lt;p&gt;For security reasons Ansible, by default, has disabled reading configuration from mounted location, therefore we have to implcity indicate path /vagrant/ansible.cfg.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Listing 1. Vagrantfile for our research&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;
Vagrant.configure("2") do |config|
  config.vm.box = "geerlingguy/centos7"
  config.vm.hostname = "awx"
  config.vm.provider "virtualbox" do |vb|
    vb.name = "AWX"
    vb.memory = "2048"
    vb.cpus = 3
  end
  config.vm.provision "shell", inline: "yum install -y git python3-pip"
  config.vm.provision "shell", inline: "pip3 install ansible==2.9.10"
  config.vm.provision "shell", inline: "echo 'export ANSIBLE_CONFIG=/vagrant/ansible.cfg' &gt;&gt; /home/vagrant/.bashrc"
end&lt;/pre&gt;

&lt;h2&gt;First tasks&lt;/h2&gt;

&lt;p&gt;In the first lines of the Ansible we specify few meta values. Most of them, like name, hosts and tasks are mandatory.
Others provide auxiliary functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Listing 2. duplicate_ec2.yml playbook first lines&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;
---
- name: yolo
  hosts: localhost
  connection: local
  gather_facts: false
  become: false
  vars:
    instance_id: i-deadbeef007&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;tasks:&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/how-to-create-ec2-duplicate-instance-ansible" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Wed, 28 Oct 2020 19:32:42 +0000</pubDate>
    <dc:creator>Tomasz Szandała</dc:creator>
    <guid isPermaLink="false">1340807 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Digging Through the DevOps Arsenal: Introducing Ansible</title>
  <link>https://www.linuxjournal.com/content/digging-through-devops-arsenal-introducing-ansible</link>
  <description>  &lt;div data-history-node-id="1340730" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/petros-koutoupis" lang="" about="https://www.linuxjournal.com/users/petros-koutoupis" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Petros Koutoupis&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;If you need to deploy hundreds of server or client nodes in parallel, maybe
on-premises or in the cloud, and you need to configure each and every single one
of them, what do you do? How do you do it? Where do you even begin?
Many configuration management frameworks exist to address most, if
not all, of these questions and concerns. Ansible is one such framework.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
You may have heard of Ansible already, but for those who haven't or don't know
what it is,
Ansible is a configuration management and provisioning tool. (I'll get to
exactly what that means shortly.) It's very similar to other tools, such as
Puppet, Chef and Salt.
&lt;/p&gt;

&lt;p&gt;
Why use Ansible? Well, because it's simple to master. I don't mean that the others are
not simple, but Ansible makes it easy for individuals to pick up quickly.
That's
because Ansible uses YAML as its base to provision, configure and deploy. And
because of this approach, tasks are executed in a specific order. During
execution, if you trip over a syntax error, it will fail once you hit it,
potentially making it easier to debug.
&lt;/p&gt;

&lt;p&gt;
Now, what's YAML? YAML (or YAML Ain't Markup Language) is
a human-readable data-serialization language mostly used to capture
configuration files. You know how JSON is easier to implement and use over
XML? Well, YAML takes a more simplistic approach than JSON. Here's an
example of a typical YAML structure containing a list:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
data:
    - var1:
        a: 1
        b: 2
    - var2:
        a: 1
        b: 2
        c: 3
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
Now, let's swing back to Ansible. Ansible is an open-source automation platform
freely available for Linux, macOS and BSD. Again, it's very simple to set up
and use, without compromising any power. Ansible is designed to aid you in
configuration management, application deployment and the automation of
assorted tasks. It works great in the realm of IT orchestration, in which you
need to run specific tasks in sequence and create a chain of events that must
happen on multiple and different servers or devices.
&lt;/p&gt;

&lt;p&gt;
Here's a good example: say you have a group of web servers behind a
load balancer. You need to upgrade those web servers, but you also need to
ensure that all but one server remains online for the upgrade process. Ansible
can handle such a complex task.
&lt;/p&gt;

&lt;p&gt;
Ansible uses SSH to manage remote systems across the network, and those
systems are required to have a local installation of not only SSH but also
Python. That means you don't have to install and configure a client-server
environment for Ansible.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/digging-through-devops-arsenal-introducing-ansible" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Wed, 07 Aug 2019 18:15:00 +0000</pubDate>
    <dc:creator>Petros Koutoupis</dc:creator>
    <guid isPermaLink="false">1340730 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Weekend Reading: Ansible</title>
  <link>https://www.linuxjournal.com/content/weekend-reading-ansible</link>
  <description>  &lt;div data-history-node-id="1339918" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/shawn-powers" lang="" about="https://www.linuxjournal.com/users/shawn-powers" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Shawn Powers&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p dir="ltr"&gt;I've written about and trained folks on various DevOps tools through the years, and although they're awesome, it's obvious that most of them are designed from the mind of a developer. There's nothing wrong with that, because approaching configuration management programmatically is the whole point. Still, it wasn't until I started playing with Ansible that I felt like it was something a sysadmin quickly would appreciate.&lt;/p&gt;

&lt;p dir="ltr"&gt;Part of that appreciation comes from the way Ansible communicates with its client computers—namely, via SSH. As sysadmins, you're all very familiar with connecting to computers via SSH, so right from the word "go", you have a better understanding of Ansible than the other alternatives.&lt;/p&gt;

&lt;p dir="ltr"&gt;With that in mind, I've written a few articles exploring how to take advantage of Ansible. It's a great system, but when I was first exposed to it, it wasn't clear how to start. It's not that the learning curve is steep. In fact, if anything, the problem was that I didn't really have that much to learn before starting to use Ansible, and that made it confusing. For example, if you don't have to install an agent program (Ansible doesn't have any software installed on the client computers), how do you start?&lt;/p&gt;

&lt;h3 dir="ltr"&gt;&lt;a href="https://www.linuxjournal.com/content/ansible-automation-framework-thinks-sysadmin"&gt;Ansible, Part I: the Automation Framework That Thinks Like a Sysadmin&lt;/a&gt;

&lt;/h3&gt;&lt;p dir="ltr"&gt;How to get started with Ansible. Shawn tells us the reason Ansible was so difficult for him at first was because it's so flexible with how to configure the server/client relationship, he didn't know what he was supposed to do. The truth is that Ansible doesn't really care how you set up the SSH system; it will utilize whatever configuration you have. This article will get you set up.
 &lt;/p&gt;

&lt;h3 dir="ltr"&gt;&lt;a href="https://www.linuxjournal.com/content/ansible-making-things-happen"&gt;Ansible, Part II: Making Things Happen&lt;/a&gt;

&lt;/h3&gt;&lt;p dir="ltr"&gt;Finally, an automation framework that thinks like a sysadmin. Ansible, you're hired.&lt;/p&gt;

&lt;p dir="ltr"&gt;Ansible is supposed to make your job easier, so the first thing you need to learn is how to do familiar tasks. For most sysadmins, that means some simple command-line work. Ansible has a few quirks when it comes to command-line utilities, but it's worth learning the nuances, because it makes for a powerful system.&lt;/p&gt;

&lt;h3 dir="ltr"&gt;&lt;a href="https://www.linuxjournal.com/content/ansible-part-iii-playbooks"&gt;Ansible, Part III: Playbooks&lt;/a&gt;

&lt;/h3&gt;&lt;p dir="ltr"&gt;Playbooks make Ansible even more powerful than before.&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/weekend-reading-ansible" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Sat, 05 Jan 2019 12:30:00 +0000</pubDate>
    <dc:creator>Shawn Powers</dc:creator>
    <guid isPermaLink="false">1339918 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Ansible, Part IV: Putting It All Together</title>
  <link>https://www.linuxjournal.com/content/ansible-part-iv-putting-it-all-together</link>
  <description>  &lt;div data-history-node-id="1339704" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/shawn-powers" lang="" about="https://www.linuxjournal.com/users/shawn-powers" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Shawn Powers&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;
&lt;em&gt;
Roles are the most complicated and yet simplest aspect of
Ansible to learn.
&lt;/em&gt;
&lt;/p&gt;

&lt;p&gt;
I've mentioned before that Ansible's ad-hoc mode often is overlooked
as just a way to learn how to use Ansible. I couldn't disagree with
that mentality any more fervently than I already do. Ad-hoc mode is
actually what I tend to use most often on a day-to-day basis. That said,
using playbooks and roles are very powerful ways to utilize Ansible's
abilities. In fact, when most people think of Ansible, they tend to
think of the roles feature, because it's the way most Ansible code is
shared. So first, it's important to understand the relationship
between ad-hoc mode, playbooks and roles.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Ad-hoc Mode&lt;/span&gt;

&lt;p&gt;
This is a bit of a review, but it's easy to forget once you start creating
playbooks. Ad-hoc mode is simply a one-liner that uses an Ansible module
to accomplish a given task on a set of computers. Something like:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
ansible cadlab -b -m yum -a "name=vim state=latest"
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
will install vim on every computer in the cadlab group. The
&lt;code&gt;-b&lt;/code&gt;
signals to elevate privilege ("become" root), the
&lt;code&gt;-m&lt;/code&gt; means to use the
&lt;code&gt;yum&lt;/code&gt; module, and the &lt;code&gt;-a&lt;/code&gt; says
what actions to take. In this case,
it's installing the latest version of vim.
&lt;/p&gt;

&lt;p&gt;
Usually when I use ad-hoc mode to install packages, I'll follow up with
something like this:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
ansible cadlab -b -m service -a "name=httpd state=started
 ↪enabled=yes"
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
That one-liner will make sure that the httpd service is running and set
to start on boot automatically (the latter is what "enabled" means). Like
I said at the beginning, I most often use Ansible's ad-hoc mode on a
day-to-day basis. When a new rollout or upgrade needs to happen though,
that's when it makes sense to create a playbook, which is a text file
that contains a bunch of Ansible commands.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Playbook Mode&lt;/span&gt;

&lt;p&gt;
I described playbooks in my last article. They are YAML- (Yet Another Markup
Language) formatted text files that contain a list of things for Ansible
to accomplish. For example, to install Apache on a lab full of computers, you'd create
a file something like this:

&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/ansible-part-iv-putting-it-all-together" hreflang="und"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Fri, 02 Mar 2018 15:31:56 +0000</pubDate>
    <dc:creator>Shawn Powers</dc:creator>
    <guid isPermaLink="false">1339704 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Ansible, Part III: Playbooks</title>
  <link>https://www.linuxjournal.com/content/ansible-part-iii-playbooks</link>
  <description>  &lt;div data-history-node-id="1339671" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/shawn-powers" lang="" about="https://www.linuxjournal.com/users/shawn-powers" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Shawn Powers&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;Playbooks make Ansible even more powerful than before.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
To be quite honest, if Ansible had nothing but its ad-hoc mode, it
still would be a powerful and useful tool for automating large numbers of
computers. In fact, if it weren't for a few features, I might consider
sticking with ad-hoc mode and adding a bunch of those ad-hoc commands to
a Bash script and be done with learning. Those few additional features,
however, make the continued effort well worth it.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Tame the Beast with YAML&lt;/span&gt;

&lt;p&gt;
Ansible goes out of its way to use an easy-to-read configuration file for
making "playbooks", which are files full of separate Ansible
"tasks". A
task is basically an ad-hoc command written out in a configuration file
that makes it more organized and easy to expand. The configuration
files use YAML, which stands for "Yet Another Markup Language".
It's an easy-to-read markup language, but it does rely on whitespace,
which isn't terribly common with most config files. A simple playbook
looks something like this:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
---

- hosts: webservers
  become: yes
  tasks:
    - name: this installs a package
      apt: name=apache2 update_cache=yes state=latest

    - name: this restarts the apache service
      service: name=apache2 enabled=yes state=restarted
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
The contents should be fairly easy to identify. It's basically two
ad-hoc commands broken up into a YAML configuration file. There are a
few important things to notice. First, every filename ends with .yaml,
and every YAML file must begin with three hyphen characters. Also, as
mentioned above, whitespace matters. Finally, when a hyphen should
precede a section and when it should just be spaced appropriately often
is confusing. Basically every new section needs to start with a - symbol,
but it's often hard to tell what should be its own section. Nevertheless,
it starts to feel natural as you create more and more playbooks.
&lt;/p&gt;

&lt;p&gt;
The above playbook would be executed by typing:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
ansible-playbook filename.yaml
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
And that is the equivalent of these two commands:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
ansible webservers -b -m apt -a "name=apache2
 ↪update_cache=yes state=latest"
ansible webservers -b -m service -a "name=apache2
 ↪enabled=yes state=restarted"
&lt;/code&gt;
&lt;/pre&gt;


&lt;span class="h3-replacement"&gt;
Handling Your Handlers&lt;/span&gt;

&lt;p&gt;
But a bit of organization is really only the beginning of why playbooks
are so powerful. First off, there's the idea of "Handlers", which are
tasks that are executed only when "notified" that a task has made a
change. How does that work exactly? Let's rewrite the above YAML file
to make the second task a handler:

&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/ansible-part-iii-playbooks" hreflang="und"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Mon, 19 Feb 2018 16:50:14 +0000</pubDate>
    <dc:creator>Shawn Powers</dc:creator>
    <guid isPermaLink="false">1339671 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Ansible: Making Things Happen</title>
  <link>https://www.linuxjournal.com/content/ansible-making-things-happen</link>
  <description>  &lt;div data-history-node-id="1339602" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/shawn-powers" lang="" about="https://www.linuxjournal.com/users/shawn-powers" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Shawn Powers&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;
&lt;em&gt;Finally, an automation framework that thinks like a sysadmin. Ansible,
you're hired.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
In my &lt;a href="http://www.linuxjournal.com/content/ansible-automation-framework-thinks-sysadmin"&gt;last article&lt;/a&gt;, I described how to configure your server and clients so
you could
connect to each client from the server. Ansible is a push-based automation
tool, so the connection is initiated from your "server", which is usually
just a workstation or a server you &lt;code&gt;ssh&lt;/code&gt; in to from
your workstation. In this article, I explain
how modules work and how you can use Ansible
in ad-hoc mode from the command line.
&lt;/p&gt;

&lt;p&gt;
Ansible is supposed to make your job easier, so the first thing you
need to learn is how to do familiar tasks. For most sysadmins, that
means some simple command-line work. Ansible has a few quirks when it
comes to command-line utilities, but it's worth learning the nuances,
because it makes for a powerful system.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Command Module&lt;/span&gt;

&lt;p&gt;
This is the safest module to execute remote commands on the client
machine. As with most Ansible modules, it requires Python to be installed
on the client, but that's it. When Ansible executes commands using the
Command Module, it does not process those commands through the user's
shell. This means some variables like &lt;code&gt;$HOME&lt;/code&gt; are not available. It also
means stream functions (redirects, pipes) don't work. If you don't
need to redirect output or to reference the user's home directory as
a shell variable, the Command Module is what you want to use. To invoke
the Command Module in ad-hoc mode, do something like this:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
ansible host_or_groupname -m command -a "whoami"
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
Your output should show &lt;code&gt;SUCCESS&lt;/code&gt; for each host referenced and then return
the user name that the user used to log in. You'll notice that the user is not
root, unless that's the user you used to connect to the client computer.
&lt;/p&gt;

&lt;p&gt;
If
you want to see the elevated user, you'll add another argument to the
&lt;code&gt;ansible&lt;/code&gt; command. You can add
&lt;code&gt;-b&lt;/code&gt; in order to "become" the elevated user
(or the sudo user). So, if you were to run the same command as above with a
"-b" flag:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
ansible host_or_groupname -b -m command -a "whoami"
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
you should see a similar result, but the &lt;code&gt;whoami&lt;/code&gt;
results should say &lt;code&gt;root&lt;/code&gt;
instead of the user you used to connect. That flag is important to use,
especially if you try to run remote commands that require root access!
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/ansible-making-things-happen" hreflang="und"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Tue, 30 Jan 2018 16:07:28 +0000</pubDate>
    <dc:creator>Shawn Powers</dc:creator>
    <guid isPermaLink="false">1339602 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Ansible: the Automation Framework That Thinks Like a Sysadmin</title>
  <link>https://www.linuxjournal.com/content/ansible-automation-framework-thinks-sysadmin</link>
  <description>  &lt;div data-history-node-id="1339558" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/shawn-powers" lang="" about="https://www.linuxjournal.com/users/shawn-powers" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Shawn Powers&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;
I've written about and trained folks on various DevOps tools through the years, and
although they're awesome, it's obvious that most of them are designed from the
mind of a developer. There's nothing wrong with that, because approaching
configuration management programmatically is the whole point. Still,
it wasn't until I started playing with Ansible that I felt like it was
something a sysadmin quickly would appreciate.
&lt;/p&gt;


&lt;p&gt;
Part of that appreciation comes from the way Ansible communicates with its
client computers—namely, via SSH. As sysadmins, you're all very familiar
with connecting to computers via SSH, so right from the word
"go", you
have a better understanding of Ansible than the other alternatives.
&lt;/p&gt;

&lt;p&gt;
With that in mind, I'm planning
to write a few articles exploring how to take advantage of
Ansible. It's a great system, but when I was first exposed to it, it wasn't
clear how to start. It's not that the learning curve is steep. In fact,
if anything, the problem was that I didn't really have that much to learn
before starting to use Ansible, and that made it confusing. For example,
if you don't have to install an agent program (Ansible doesn't have any
software installed on the client computers), how do you start?
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Getting to the Starting Line&lt;/span&gt;

&lt;p&gt;
The reason Ansible was so difficult for me at first is because it's so
flexible with how to configure the server/client relationship, I
didn't know what I was supposed to do. The truth is that Ansible doesn't
really care how you set up the SSH system; it will utilize whatever
configuration you have. There are just a couple things to consider:
&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;
&lt;p&gt;
Ansible needs to connect to the client computer via SSH.
&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;
Once connected, Ansible needs to elevate privilege so it can configure
the system, install packages and so on.
&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;
Unfortunately, those two considerations really open a can of
worms. Connecting to a remote computer and elevating privilege is a
scary thing to allow. For some reason, it feels less vulnerable when you
simply install an agent on the remote computer and let Chef or Puppet
handle privilege escalation. It's not that Ansible is any less secure,
but rather, it puts the security decisions in your hands.
&lt;/p&gt;

&lt;p&gt;
Next I'm going to
list a bunch of potential configurations, along with the pros and cons
of each. This isn't an exhaustive list, but it should get you thinking
along the right lines for what will be ideal in your environment. I
also should note that I'm not going to mention systems like Vagrant,
because although Vagrant is wonderful for building a quick infrastructure
for testing and developing, it's so very different from a bunch of
servers that the considerations are too dissimilar really to compare.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Some SSH Scenarios&lt;/span&gt;

&lt;p&gt;
&lt;em&gt;1) SSHing into remote computer as root with password in Ansible
config.&lt;/em&gt;
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/ansible-automation-framework-thinks-sysadmin" hreflang="und"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Fri, 05 Jan 2018 13:02:34 +0000</pubDate>
    <dc:creator>Shawn Powers</dc:creator>
    <guid isPermaLink="false">1339558 at https://www.linuxjournal.com</guid>
    </item>

  </channel>
</rss>
