<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Tag: CentOS - Ryan Daniels</title>
	<atom:link href="https://ryandaniels.ca/blog/tag/centos/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Thu, 02 Jul 2020 02:23:44 +0000</lastBuildDate>
	<language>en-CA</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://ryandaniels.ca/wp-content/uploads/2019/07/img_5907-small-blur-square-100x100.jpg</url>
	<title>Tag: CentOS - Ryan Daniels</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">22628916</site>	<item>
		<title>Secure Docker with iptables firewall and Ansible</title>
		<link>https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 24 May 2020 19:11:41 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=2290</guid>

					<description><![CDATA[<figure class="alignleft wp-block-image size-thumbnail"><img src="https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-200x300.jpg" alt="" class="wp-image-2489"/></figure>
<p>Out of the box, security with Docker (and Docker Swarm) over the network is bad. Okay, that's not entirely true. Out of the box when you have no containers started, it's fine. But after you start a container, and if you publish a port, they are exposed to the outside world by default. And it's not easy to fix. You need to create a custom Docker firewall with iptables.<br />
&#160;</p>
<p>The post <a href="https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/">Secure Docker with iptables firewall and Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Out of the box, security with Docker (and Docker Swarm) over the network is bad. Okay, that&#8217;s not entirely true. Out of the box when you have no containers started, it&#8217;s fine. But after you start a container, and if you publish a port, they are exposed to the outside world by default. And it&#8217;s not easy to fix. You need to create a custom Docker firewall with iptables.</p>



<p>Let&#8217;s discuss the background of firewall issues with Docker, and a working solution for my use case (either setup manually or using Ansible). By the end we will use a firewall on the server to lock down everything by default, only allowing my trusted IPs! With the option to open specified ports publicly (like SSH).</p>



<p>Note: This solution works with CentOS 7, RHEL 7, Ubuntu 18.04, and Ubuntu 20.04.</p>



<span id="more-2290"></span>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-5708b17e-d0f5-4528-8221-706c39a8a865      "
					data-scroll= ""
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							Table Of Contents						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#background" class="uagb-toc-link__trigger">Background</a><li class="uagb-toc__list"><a href="#roll-your-own-solution" class="uagb-toc-link__trigger">Roll your own solution</a><li class="uagb-toc__list"><a href="#problems-i-need-to-solve" class="uagb-toc-link__trigger">Problems I need to solve</a><li class="uagb-toc__list"><a href="#solution-docker-firewall-with-iptables-and-ipset" class="uagb-toc-link__trigger">Solution &#8211; Docker firewall with iptables and ipset</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#high-level-summary" class="uagb-toc-link__trigger">High level summary</a></li></ul></li><li class="uagb-toc__list"><a href="#warnings" class="uagb-toc-link__trigger">Warnings</a><li class="uagb-toc__list"><a href="#the-manual-way" class="uagb-toc-link__trigger">The manual way</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#prep" class="uagb-toc-link__trigger">Prep</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#configure-ipset" class="uagb-toc-link__trigger">Configure ipset</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#configure-iptables" class="uagb-toc-link__trigger">Configure iptables</a></li></ul></li></ul></li><li class="uagb-toc__list"><a href="#the-automatic-way-with-ansible" class="uagb-toc-link__trigger">The Automatic way with Ansible</a><li class="uagb-toc__list"><a href="#conclusion" class="uagb-toc-link__trigger">Conclusion</a><li class="uagb-toc__list"><a href="#references" class="uagb-toc-link__trigger">References</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#background-for-dockers-undocumented-use-of-iptables-input-chain" class="uagb-toc-link__trigger">Background for Docker&#039;s undocumented use of iptables INPUT chain</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#references-and-links" class="uagb-toc-link__trigger">References and links</a></ul></ul></ul></ol>					</div>
									</div>
				</div>
			


<h2 class="wp-block-heading">Background</h2>



<div class="wp-block-image"><figure class="alignright size-medium"><img fetchpriority="high" decoding="async" width="400" height="600" src="https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-400x600.jpg" alt="Docker punches a hole through firewall" class="wp-image-2489" srcset="https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-400x600.jpg 400w, https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-480x720.jpg 480w, https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-200x300.jpg 200w, https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye.jpg 533w" sizes="(max-width: 400px) 100vw, 400px" /><figcaption><sup>Image credit: <a rel="noreferrer noopener" href="https://www.pexels.com/photo/brown-human-eye-2873058/" target="_blank">Jonathan Borba</a></sup></figcaption></figure></div>



<p>Firstly, even if you were using a firewall like iptables, Docker makes that useless. Docker punches a whole right through your firewall!</p>



<p>And if you <a href="https://ryandaniels.ca/blog/ansible-manage-firewalld/">try another firewall, like firewalld</a>? Docker Swarm (and even regular Docker) with firewalld is a complete mess. Restart the firewalld service, or change the firewalld config, and you lost all the config that Docker needed. Now you have to restart Docker! What happens if the firewalld service failed and restarted? That Docker Swarm node is out of service.</p>



<p>Keep in mind, when I mention Docker, it means the regular Docker Engine. Docker Swarm means SwarmKit, which is the newer way of using Swarm. (The old way is the standalone solution which is old and not referenced at all here).</p>



<p>There are many attempts to solve this problem by users of Docker. Unfortunately the Docker team has been pretty quiet about these issues. They recommend a manual user solution, and to disable Docker&#8217;s use of iptables. I&#8217;m speculating here, but it seems like any future change from Docker will likely be a breaking change since this is a complicated issue to fix.</p>



<p>The attempted solutions (from users) are not very straight forward for a normal Docker user. And that&#8217;s the real issue. On top of that, out of the box (after you start one service with a published port), there is no security at the network layer. Anyone can connect to an exposed container&#8217;s port. Most importantly, even if you think you have a firewall protecting you.. Wrong, you don&#8217;t! With normal Docker, you can bind your service to your localhost which helps. But what about Docker Swarm? Nope, that doesn&#8217;t work.</p>



<p>There&#8217;s a great article about &#8220;<a rel="noreferrer noopener" href="https://utcc.utoronto.ca/~cks/space/blog/tech/SecurityChoiceProblem" data-type="URL" data-id="https://utcc.utoronto.ca/~cks/space/blog/tech/SecurityChoiceProblem" target="_blank">The problem of forcing users to make choices (in security)</a>.&#8221; Definitely worth the read!</p>



<h2 class="wp-block-heading">Roll your own solution</h2>



<p>Until this is actually addressed in Docker, our only hope is to find the simplest solution possible. And turning off iptables integration in Docker is unacceptable (which is constantly recommended by the Docker developers). The other option is to move on from Docker and/or Docker Swarm. I hear this thing called Kubernetes is pretty great. Anyways, back to Docker. <br>Many people have spent hours trying to learn, and figure out iptables as a solution to this. You need to roll your own solution apparently! So iptables is probably the best approach, since that is what Docker needs to use to do it&#8217;s magic (and most other firewalls are just a wrapper for iptables anyway depending on your OS).</p>



<p>Something <s>fun</s> I found out while testing this, <a href="https://ryandaniels.ca/blog/docker-iptables-input-chain/">Docker Swarm uses iptables in an undocumented way</a>. Docker Swarm uses the iptables INPUT chain! It&#8217;s only for encrypted overlay networks. But it&#8217;s not very fun realizing that! All of a sudden rules are being appended to the INPUT chain.</p>



<p>Okay, enough backstory. On with my futile attempt to roll my own solution. This took way longer than I thought it would! But it does work! Currently it works at least.. (That&#8217;s why I use the word futile!)</p>



<h2 class="wp-block-heading">Problems I need to solve</h2>



<ol class="wp-block-list"><li>Only allow traffic from multiple &#8220;trusted&#8221; IP addresses to my servers. Not all of these IPs will be in the same &#8220;IP block/range&#8221; either. This will be to all services running directly on the server, and also all of the Docker containers.</li><li>Let only specific ports be publicly accessible, like SSH.</li><li>I&#8217;m not managing which containers are accessible through the firewall. Meaning, I&#8217;m not manually adding ports into my firewall solution. That kind of manual work is not happening. I need a dynamic, and flexible solution that blocks by default except to my trusted IPs.</li><li>The firewall solution must be simple. More complex means more room for error.</li><li>The firewall solution must not impact performance significantly.</li><li>Restarting the firewall won&#8217;t break Docker. </li><li>Restarting Docker won&#8217;t break the firewall.</li><li>No impact to running server processes or Docker services when making a change. Things need to keep working! <br>Firewall changes need to happen online and not impact Docker. Meaning I can&#8217;t be restarting Docker because I made a firewall change.<br>Docker &#8220;changes&#8221; need to happen online. Meaning I can&#8217;t be restarting the firewall because I made a Docker change. (A Docker &#8220;change&#8221; means starting/stopping a container).</li></ol>



<p>That sounds very simple! Unfortunately, it is not with Docker (and Docker Swarm).</p>



<h2 class="wp-block-heading">Solution &#8211; Docker firewall with iptables and ipset</h2>



<p>If you don&#8217;t know much about iptables, or ipset, that&#8217;s okay. You don&#8217;t really need to know. You should have some basic understandings though, so you don&#8217;t break your servers! The <a rel="noreferrer noopener" href="https://wiki.archlinux.org/index.php/Iptables#Chains" target="_blank">Arch Linux wiki</a> has great information about iptables. Including this helpful <a rel="noreferrer noopener" href="https://www.frozentux.net/iptables-tutorial/chunkyhtml/images/tables_traverse.jpg" target="_blank" rel="lightbox[2290]">visual</a> about the iptables flow.</p>



<p>Note: This solution works with CentOS 7, RHEL 7, Ubuntu 18.04, and Ubuntu 20.04.</p>



<h3 class="wp-block-heading">High level summary</h3>



<p>iptables with ipset will handle all of this for us. And keep our servers, and Docker locked down from the network level. </p>



<p>In this solution, we will use the iptables INPUT chain to jump to another chain (let&#8217;s call our custom chain FILTERS), but return if there&#8217;s some legitimate looking traffic, so the Swarm overlay can do whatever it wants in INPUT with IPSEC, or whatever it is appending to INPUT.<br>Inside our custom chain FILTERS, we drop everything that doesn&#8217;t match our trusted list of IPs. We also allow our SSH port and the basic default iptables stuff.. You can also add any OS port to be publicly accessible.<br>The DOCKER-USER chain only needs a few entries. Any internal Docker traffic is returned, and it will drop any other traffic that&#8217;s not in our allowed IP list. You can also add any container port to be publicly accessible.</p>



<p>One of the dangers with this approach is if Docker changes it&#8217;s behaviour our firewall could break, or our Docker services could stop working. Since Docker doesn&#8217;t offer any solution for their users, we need our own solution. So keep in mind that you need to test this when upgrading to a new version of Docker. That is the trade-off with a &#8220;roll your own&#8221; solution. But what choice do we have?</p>



<p>I&#8217;ve created an <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Role: iptables for Docker</a>, on <a rel="noreferrer noopener" href="https://github.com/ryandaniels/ansible-role-iptables-docker" target="_blank">GitHub</a> and <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Galaxy</a>.</p>



<h2 class="wp-block-heading">Warnings</h2>



<p><strong>Warning: Be sure you have everything needed in your configuration. Once the iptables firewall is started it blocks anything that wasn’t added! Don&#8217;t lock yourself out of your server. Be sure to have another way to connect, like a console.</strong></p>



<p><strong>Disclaimer: Keep in mind, you should test all of this in your lab or staging environments. I can’t guarantee this will be 100% safe and can’t be held responsible for anything going wrong!</strong></p>



<p><strong>SELinux Bug</strong>: If using SELinux, currently there&#8217;s a bug with SELinux which prevents saving the iptables rules to the iptables.save file.<br><strong>Impact</strong>: Saving the iptables rules a 2nd time will silently fail. Workaround has been added so SELinux allows chmod to interact with the iptables.save file. <a rel="noreferrer noopener" href="https://github.com/ryandaniels/ansible-role-iptables-docker/blob/master/README.md#selinux-manual-workaround-for-iptables-and-chmod" target="_blank">See notes on GitHub for SELinux workaround steps</a>. Alternatively you could disable SELinux, but that&#8217;s not recommended. Bug report: <a rel="noreferrer noopener" href="https://bugs.centos.org/view.php?id=12648" target="_blank">https://bugs.centos.org/view.php?id=12648</a></p>



<h2 class="wp-block-heading">The manual way</h2>



<p>Run the commands below. These commands are only for CentOS/RHEL 7. If you don&#8217;t want to do this manually, jump to the <a href="#the-automatic-way-with-ansible">Automatic section, using Ansible</a> (which also works with Ubuntu).</p>



<h3 class="wp-block-heading">Prep</h3>



<p>Make note of what you already have in iptables (if you are already using it). Be sure you have some background with iptables, since you could break things!</p>



<pre class="wp-block-code"><code># iptables -nvL --line-numbers</code></pre>



<p>Install the required packages for CentOS / RHEL:</p>



<pre class="wp-block-code"><code># yum install iptables iptables-services ipset ipset-service</code></pre>



<h3 class="wp-block-heading">Configure ipset</h3>



<p>ipset allows you to add a list of IPs that you can use with iptables. In our case, we will add a list of IPs we want to be able to connect to our servers.</p>



<p>Configure ipset with a setname of <code>ip_allow</code>.<br>Add IPs you want to allow. Change the IPs below to your actual trusted/allowed IP ranges. Be sure to include your Docker server IPs here, because if you don&#8217;t they can&#8217;t communicate with eachother:</p>



<pre class="wp-block-code"><code># mkdir -p /etc/sysconfig/ipset.d
# vi /etc/sysconfig/ipset.d/ip_allow.set

create -exist ip_allow hash:ip family inet hashsize 1024 maxelem 65536
add ip_allow 192.168.1.123
add ip_allow 192.168.100.0/24
add ip_allow 192.168.101.0/24
add ip_allow 192.168.102.0/24</code></pre>



<p>Start, and Enable the ipset service:</p>



<pre class="wp-block-code"><code># systemctl status ipset
# systemctl start ipset
# systemctl enable ipset</code></pre>



<p>See what ipset has in it&#8217;s loaded configuration:</p>



<pre class="wp-block-code"><code># ipset list | head</code></pre>



<p>Important: Make note of the size of &#8220;Number of entries&#8221;. If that number is close to the maxelem size (65536), then you need to delete the ipset and re-create it with a larger max size. If you only use a few IP ranges like above, you don&#8217;t need to worry and will be well below the limit.</p>



<h3 class="wp-block-heading">Configure iptables</h3>



<p>Next up, iptables. iptables is our solution for a firewall. We will create a file with our rules and then add those rules into iptables. The important part is to not flush the existing rules if you are already using Docker  (or Docker Swarm) on your server.</p>



<p>Create an iptables file to use with iptables-restore, to add the rules into iptables:</p>



<pre class="wp-block-code"><code># vi iptables-rules.txt</code></pre>



<p>Add below to the file. There is a lot going on here..</p>



<pre class="wp-block-code"><code>*filter
:DOCKER-USER - &#91;0:0]
:FILTERS - &#91;0:0]
#Can't flush INPUT. wipes out docker swarm encrypted overlay rules
#-F INPUT
#Use ansible or run manually once instead to add -I INPUT -j FILTERS
#-I INPUT -j FILTERS
-F DOCKER-USER
-A DOCKER-USER -m state --state RELATED,ESTABLISHED -j RETURN
-A DOCKER-USER -i docker_gwbridge -j RETURN
-A DOCKER-USER -s 172.18.0.0/16 -j RETURN
-A DOCKER-USER -i docker0 -j RETURN
-A DOCKER-USER -s 172.17.0.0/16 -j RETURN
#Below Docker ports open to everyone if uncommented
#-A DOCKER-USER -p tcp -m tcp -m multiport --dports 8000,8001 -j RETURN
#-A DOCKER-USER -p udp -m udp -m multiport --dports 9000,9001 -j RETURN
-A DOCKER-USER -m set ! --match-set ip_allow src -j DROP
-A DOCKER-USER -j RETURN
-F FILTERS
#Because Docker Swarm encrypted overlay network just appends rules to INPUT. Has to be at top unfortunately
-A FILTERS -p udp -m policy --dir in --pol ipsec -m udp -m set --match-set ip_allow src --dport 4789 -j RETURN
-A FILTERS -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FILTERS -p icmp -j ACCEPT
-A FILTERS -i lo -j ACCEPT
#Below OS ports open to everyone if uncommented
-A FILTERS -p tcp -m state --state NEW -m tcp -m multiport --dports 22 -j ACCEPT
#-A FILTERS -p udp -m udp -m multiport --dports 53,123 -j ACCEPT
-A FILTERS -m set ! --match-set ip_allow src -j DROP
-A FILTERS -j RETURN
COMMIT</code></pre>



<p>Use iptables-restore to add the above rules into iptables. The very important flag is <code>-n</code>. That makes sure we don&#8217;t flush the iptables rules if we have rules already in Docker (or Docker Swarm).</p>



<pre class="wp-block-code"><code># iptables-restore -n &lt; iptables-rules.txt</code></pre>



<p>Next, add a rule to the INPUT chain, so we start using the new rules in FILTERS. It has to be at the top, and only needs to be added once:</p>



<pre class="wp-block-code"><code># iptables -I INPUT 1 -j FILTERS</code></pre>



<p>Save the iptables rules:</p>



<pre class="wp-block-code"><code># /usr/libexec/iptables/iptables.init save</code></pre>



<p>That will save any existing and our new iptables rules to the iptables configuration file so it will be persistent after a reboot.</p>



<p>In addition, it was needed to run the above iptables command manually since we want to ensure it&#8217;s only inserted once. And we can&#8217;t flush the INPUT chain to ensure that since Docker Swarm could have rules there already.</p>



<p>Start and Enable the iptables service:</p>



<pre class="wp-block-code"><code># systemctl status iptables
# systemctl start iptables
# systemctl enable iptables</code></pre>



<p>If you want to customize the iptables rules to allow more ports to be open to everyone, just add the port to the appropriate rule in the iptables file (tcp or udp), then re-run the same commands from above:</p>



<pre class="wp-block-code"><code># iptables-restore -n &lt; iptables-rules.txt
# /usr/libexec/iptables/iptables.init save</code></pre>



<p><strong>Don&#8217;t miss the <a href="#warnings">Warnings</a> from above! Especially about SELinux.</strong></p>



<p>If you don&#8217;t want to do all of that manually, and you use Ansible, then do this instead..</p>



<h2 class="wp-block-heading">The Automatic way with Ansible</h2>



<p>Manually run all of the above, on every Docker server is not ideal. Let&#8217;s use Ansible instead!</p>



<p>I&#8217;ve created an <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Role: iptables for Docker</a>, on <a rel="noreferrer noopener" href="https://github.com/ryandaniels/ansible-role-iptables-docker" target="_blank">GitHub</a> and <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Galaxy</a>. </p>



<p>This works on CentOS 7, RHEL 7, Ubuntu 18.04, and Ubuntu 20.04.</p>



<p>Install the Ansible Role using Ansible Galaxy:</p>



<pre class="wp-block-code"><code>$ ansible-galaxy install ryandaniels.iptables_docker</code></pre>



<p>Or, clone the GitHub project:</p>



<pre class="wp-block-code"><code>$ git clone https://github.com/ryandaniels/ansible-role-iptables-docker.git roles/ryandaniels.iptables_docker</code></pre>



<p>Create the Ansible Playbook, called iptables_docker.yml:</p>



<pre class="wp-block-code"><code>---
- hosts: '{{ inventory }}'
  become: yes
  vars:
    # Use this role
    iptables_docker_managed: true
  roles:
  - ryandaniels.iptables_docker</code></pre>



<p>Make configuration changes to add desired IP addresses and ports as needed.</p>



<p><strong>Don&#8217;t miss the <a href="#warnings">Warnings</a> from above!</strong></p>



<p>Then run the playbook:</p>



<pre class="wp-block-code"><code>$ ansible-playbook iptables_docker.yml --extra-vars "inventory=centos7" -i hosts-dev</code></pre>



<h2 class="wp-block-heading">Conclusion</h2>



<p>In conclusion, now we have secured our Docker (and Docker Swarm) environments using Ansible to perform the installation and configuration of iptables! None of our Docker published ports are exposed to the world, unless we want them to be! We have created a custom Docker firewall with iptables. Hopefully, some day this will be the default behaviour and shipped with Docker out of the box! Dare to dream. Security is hard.</p>



<h2 class="wp-block-heading">References</h2>



<h3 class="wp-block-heading">Background for Docker&#8217;s undocumented use of iptables INPUT chain</h3>



<p><a href="https://ryandaniels.ca/blog/docker-iptables-input-chain/">See my previous post about this</a>.</p>



<h3 class="wp-block-heading">References and links</h3>



<p>References, notes, and links about the Docker firewall discussion:</p>



<ul class="wp-block-list"><li><a rel="noreferrer noopener" href="https://docs.docker.com/network/overlay/#encrypt-traffic-on-an-overlay-network" target="_blank">Docker Documentation &#8211; Overlay Networks</a></li><li><a rel="noreferrer noopener" href="https://github.com/docker/for-linux/issues/690" target="_blank">Docker bypasses ufw firewall rules</a></li><li><a rel="noreferrer noopener" href="https://unrouted.io/2017/08/15/docker-firewall/" target="_blank">unrouted</a> &#8211; Solution using iptables. Not for Swarm. It clobbers the INPUT chain, which is used by encrypted overlay with Docker Swarm</li><li><a rel="noreferrer noopener" href="https://github.com/moby/moby/issues/22054" target="_blank">The big thread about Docker and a firewall</a></li><li><a rel="noreferrer noopener" href="https://wiki.archlinux.org/index.php/Iptables#Chains" target="_blank">Arch Linux wiki to the rescue to show iptables</a> flow which links to a <a rel="noreferrer noopener" href="https://www.frozentux.net/iptables-tutorial/chunkyhtml/images/tables_traverse.jpg" target="_blank" rel="lightbox[2290]">great visual</a><br><br></li></ul>
<p>The post <a href="https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/">Secure Docker with iptables firewall and Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2290</post-id>	</item>
		<item>
		<title>Manage firewalld with Ansible</title>
		<link>https://ryandaniels.ca/blog/ansible-manage-firewalld/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 19 Apr 2020 21:45:00 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=2180</guid>

					<description><![CDATA[<p><a href="https://ryandaniels.ca/blog/ansible-manage-firewalld/"><img class="alignleft size-thumbnail wp-image-1170" src="https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo-e1517962271957-150x150.png" alt="Ansible manage firewalld" width="150" height="150" /></a> Managing firewalld can be a tricky. Especially if you have many servers to manage. Ansible can help manage firewalld rules for you!</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-manage-firewalld/">Manage firewalld with Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Managing firewalld can be a tricky. Especially if you have many servers to manage. Ansible can help manage firewalld rules for you!</p>



<span id="more-2180"></span>



<h2 class="wp-block-heading">Background on firewalld</h2>



<p><a rel="noreferrer noopener" href="https://firewalld.org/" target="_blank">Firewalld</a> is a firewall which runs on many Linux distributions. It is software which runs on a server, and is used to locally secure the server. For example, it can restrict which ports are available for all source IPs, or it can further restrict access by allowing only certain IPs to a specific port (and zone). Check out the <a rel="noreferrer noopener" href="https://firewalld.org/documentation/" target="_blank">documentation</a> to read more about the features of firewalld.</p>



<p>Everything is blocked when firewalld starts! The only exception is for ssh on port 22. This is normally what you want on a new server. </p>



<h2 class="wp-block-heading">Problem</h2>



<p>However, firewalld isn&#8217;t with out it&#8217;s limitations. To run commands to configure which ports you want to allow through firewalld, you need to have the firewalld service running. But, what if you are adding firewalld to a server that has an application which is already in use? As soon as you start firewalld, it will be blocked!</p>



<p>There are two ways around this. </p>



<ol class="wp-block-list"><li>Copy your firewalld config files in the right place, with all the right ports, zones, etc. And then start firewalld. This can work. But having Ansible copy files around and deal with all that is a challenge since firewalld behaves a certain way.</li><li>Use the &#8220;offline&#8221; firewalld commands!</li></ol>



<p>Let&#8217;s explore options 2. And lucky for us, we want to use Ansible to help us manage this configuration. And, Ansible can make use of &#8220;offline&#8221; mode.<br>But, unlucky for us, the Ansible module which handles firewalld can&#8217;t do everything. (At least not everything that I want it to do).</p>



<p>I want the configuration for firewalld to be as simple as possible. I don&#8217;t want the configuration for services in one place, and the configuration for ports in another.<br>But more importantly, I don&#8217;t want any service interruption.</p>



<h2 class="wp-block-heading">Solution</h2>



<p>Create my own Ansible role that does what I want.</p>



<p>If you&#8217;re new to Ansible, check out my <a href="https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/">Ansible Getting Started Guide</a>.</p>



<p>I want firewalld to behave in a certain way. Meaning if I have an application already running, and I want firewalld to start restricting access, I don&#8217;t want an outage on that application as soon as I start up the firewalld service on the server.</p>



<h2 class="wp-block-heading">Firewalld Limitations</h2>



<p>Firewalld does have some limitations. You should be aware of this before using it.<br>Anything firewalld is not aware of in the back-end (for example if using iptables), will be removed since firewalld wants to be the single source of truth for firewall rules.<br>This is why firewalld and Docker do not get along.<br>See details from: <a rel="noreferrer noopener" href="https://success.docker.com/article/why-am-i-having-network-problems-after-firewalld-is-restarted" target="_blank">here</a>, <a rel="noreferrer noopener" href="https://www.tripwire.com/state-of-security/devops/psa-beware-exposing-ports-docker/" target="_blank">here</a>, and <a rel="noreferrer noopener" href="https://docs.docker.com/network/iptables/" target="_blank">here</a>.</p>



<p>In case you missed that..<br><strong>Do not use firewalld and Docker.</strong><br><strong>Update</strong>: Instead, if you need a solution to work with Docker try using iptables directly. See my post about <a href="https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/">securing Docker with iptables and Ansible</a>.</p>



<h2 class="wp-block-heading">Firewalld Ansible Role</h2>



<div class="wp-block-image"><figure class="alignright size-medium"><img decoding="async" width="244" height="300" src="https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo-244x300.png" alt="Ansible manage firewalld" class="wp-image-1170" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo-244x300.png 244w, https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo.png 256w" sizes="(max-width: 244px) 100vw, 244px" /></figure></div>



<p>You can find my <a rel="noreferrer noopener" href="https://github.com/ryandaniels/ansible-role-firewalld" target="_blank">firewalld Ansible Role on GitHub</a> or in <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/firewalld" target="_blank">Ansible Galaxy</a>.</p>



<p>This Ansible Role manages firewalld in offline and persistent mode only. I don&#8217;t want to mess around with non-persistent changes. And using online mode is not an option.</p>



<p>It uses the <a rel="noreferrer noopener" href="https://docs.ansible.com/ansible/latest/modules/firewalld_module.html" target="_blank">Ansible module for firewalld</a> for a few things, but most changes have to be done using the command module. Specifically: &#8220;firewall-offline-cmd&#8221;.</p>



<p>Why? What&#8217;s the benefit doing it this way? It let&#8217;s you create your own custom <a rel="noreferrer noopener" href="https://firewalld.org/documentation/service/" target="_blank">service</a> in firewalld. Even built-in firewalld services can be used, and easily modified. For example, moving the ssh port from 22 to something else. (Warning, be careful changing your SSH port. You could lock yourself out!)</p>



<p>Here&#8217;s a short example of the configuration:</p>



<pre class="wp-block-code"><code>rhel_firewalld_zone_source:
  - zone: internal
    state: enabled
    source:
      - "192.168.22.64/26"
      - "192.168.23.64/26"

rhel_firewalld_custom_service:
  - name: zabbix-agent
    zone: public
    state: enabled
    port_protocol:
    # - 10050/tcp
      - 3333/tcp
  - name: openvpn
    zone: public
    state: enabled
  - name: app123-public
    zone: public
    state: enabled
    description: app123 firewall rules for public zone
    port_protocol:
      - 5000/tcp
  - name: app123-internal
    zone: internal
    state: enabled
    description: app123 firewall rules for internal zone
    port_protocol:
      - 8080/tcp
      - 9000/tcp</code></pre>



<p>In the variable <code>rhel_firewalld_zone_source</code>:<br>This will configure the Zone named <code>internal</code> to only allow IP ranges that are in <code>source</code>.</p>



<p>In the variable <code>rhel_firewalld_custom_service</code>:<br>This will configure the <code>zabbix-agent</code> service (which is actually built-in) for the zone <code>public</code>, but not use the default port (of 10050, commented out for demonstration). Instead it&#8217;s using port 3333.<br>The <code>openvpn</code> service is added to the zone <code>public</code>, and will just use the default configuration (since this is also a built-in firewalld service). You need to know it&#8217;s built-in, if you don&#8217;t specify a port. So it&#8217;s usually better to just specify a port all the time!<br>Last, there are two custom services, <code>app123-public</code> and <code>app123-internal</code>, which are added to their defined zones. They are also adding port 5000 using tcp (attached to the public zone), and adding ports 8080 and 9000 both using tcp (attached to the internal zone).</p>



<p>If you decide you want to change a port, just remove it from the configuration.</p>



<p><a href="https://github.com/ryandaniels/ansible-role-firewalld" target="_blank" rel="noreferrer noopener">More details are on GitHub. Be sure to read the README!</a></p>



<h2 class="wp-block-heading">Getting Started &#8211; Ansible firewalld</h2>



<p>Install from Ansible Galaxy:</p>



<pre class="wp-block-code"><code>ansible-galaxy install ryandaniels.firewalld</code></pre>



<p>Or, clone the GitHub project:</p>



<pre class="wp-block-code"><code>git clone https://github.com/ryandaniels/ansible-role-firewalld.git roles/firewalld</code></pre>



<p>Create the Ansible Playbook, called firewalld.yml:</p>



<pre class="wp-block-preformatted">---
- hosts: '{{ inventory }}'
  become: yes
  vars:
    # Use this role
    rhel_firewalld_managed: true
  roles:
  - firewalld</pre>



<p>Make configuration changes add desired firewalld services and ports. </p>



<p><strong>Warning: Be sure you have everything needed in your configuration. Once firewalld is started it blocks anything that wasn&#8217;t added!</strong></p>



<p><strong>Disclaimer: Keep in mind, you should test all of this in your lab or staging environments. I can&#8217;t guarantee this will be 100% safe and can&#8217;t be held responsible for anything going wrong!</strong></p>



<p>Then run the playbook:</p>



<pre class="wp-block-code"><code>ansible-playbook firewalld.yml --extra-vars "inventory=centos7" -i hosts-dev</code></pre>



<h2 class="wp-block-heading">Conclusion</h2>



<p>In conclusion, Ansible is now being used to manage firewalld rules! We have a custom firewalld service created using two different zones. The built-in firewalld services are also enabled, but we don&#8217;t really care they are built-in, since we can change the port they use if we want.<br>We have a nice and simple configuration, and this was all done in &#8220;offline&#8221; mode so there was no impact to any existing services using the ports.</p>



<p>Again, your mileage may vary. Always test in your lab or staging environment first! I&#8217;m not responsible for anything you break. </p>



<p>Stay safe!</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-manage-firewalld/">Manage firewalld with Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2180</post-id>	</item>
		<item>
		<title>User Management with Ansible</title>
		<link>https://ryandaniels.ca/blog/ansible-user-management/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Fri, 02 Mar 2018 13:03:28 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Jenkins]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1251</guid>

					<description><![CDATA[<p>Ansible is a great tool to automate all the things. Another task it can help to automate is user management.  This guide will be talking specifically about user management on Linux servers like Red Hat Enterprise Linux (RHEL), CentOS, or Ubuntu. Ansible can handle this task!</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-user-management/">User Management with Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Ansible is a great tool to automate all the things. Another task it can help to automate is user management.  This guide will be talking specifically about user management on Linux servers like Red Hat Enterprise Linux (RHEL), CentOS, or Ubuntu.</p>
<p><span id="more-1251"></span></p>
<h2>What&#8217;s the problem?</h2>
<p>If you have multiple servers to manage, it can be a pain to manually add a new user, change a password, or lock an old account. Manually logging into all of your servers and performing these tasks is a real pain, and a huge waste of time.</p>
<p>Luckily there are several solutions.</p>
<h2>Solution: Red Hat IDM</h2>
<p>There are many different solutions for user management. <a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/linux_domain_identity_authentication_and_policy_guide/index" target="_blank" rel="noopener noreferrer">Red Hat Identity Management</a> (IDM) is a very good solution that works with many Linux servers. IDM is a central location that holds all the user configuration. And it can even connect to Windows Active Directory.</p>
<p>However, if you don&#8217;t have a subscription to Red Hat Enterprise Linux there are other options.</p>
<h2>Solution: FreeIPA</h2>
<p><a href="https://www.freeipa.org/page/About" target="_blank" rel="noopener noreferrer">FreeIPA</a> is the upstream open source project for Red Hat Identify Management. So you can download the FreeIPA package and follow one of many available tutorials for setting up a <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-centralized-linux-authentication-with-freeipa-on-centos-7" target="_blank" rel="noopener noreferrer">server</a> and <a href="https://www.digitalocean.com/community/tutorials/how-to-configure-a-freeipa-client-on-centos-7" target="_blank" rel="noopener noreferrer">client</a>.</p>
<h2>Solution: Ansible for user management</h2>
<p>If the above solutions seem too complicated there&#8217;s another option. However, you should really take some time to setup user management properly. Use FreeIPA. It&#8217;s free!</p>
<p>But, if you want to use another solution while you are setting up FreeIPA, and you already have Ansible as part of your environment then you have another option. Ansible can do this of course!</p>
<p>The reason Ansible is a decent option for user management is because it is idempotent. This means, Ansible will only make a change if the change is needed to get to the desired state. So you can run the same Ansible Playbook multiple times, and if the Ansible tasks are written properly Ansible will only make a change the first time.</p>
<p>Just keep in mind, I warned you to use FreeIPA. This solution is not &#8220;enterprise&#8221; grade. But it certainly works for certain scenarios, like in a lab environment. And if you want to use Ansible for something new, there is a user management <a href="https://github.com/ryandaniels/ansible-role-create-users" target="_blank" rel="noopener noreferrer">role available on GitHub</a> or on <a href="https://galaxy.ansible.com/ryandaniels/create_users" target="_blank" rel="noopener noreferrer">Ansible Galaxy</a>.</p>
<p>If you aren&#8217;t familiar with Ansible, check out my <a href="https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/">Getting Started with Ansible guide</a>.</p>
<p>This Ansible role is tested on:</p>
<ul>
<li>Ubuntu</li>
<li>Red Hat Enterprise Linux (RHEL) 7.x, 6.5, 5.9</li>
<li>CentOS 7.x, 6.5, 5.9</li>
</ul>
<h3>What this user management Ansible role does</h3>
<p><a href="https://github.com/ryandaniels/ansible-role-create-users" target="_blank" rel="noopener noreferrer">This role</a> will manage users in the user list configuration file (list is in the file vars/lab_users.secret in the example below).<br />
It can add users, change passwords, lock/unlock user accounts, manage sudo access (per user), add ssh key(s) for ssh key based authentication.<br />
This is done on a per &#8220;group&#8221; basis (using Ansible group variables), as set in the configuration file. The group comes from the Ansible group as set for a server in the inventory file.</p>
<p>Note: Deleting users is not done on purpose.</p>
<p>The great thing about Ansible Playbooks, if you don&#8217;t like something it&#8217;s easy enough to modify.</p>
<h3>Install the Ansible user management role</h3>
<p>First let&#8217;s install the Ansible role to manage users into your Ansible control server:</p>
<pre><code>$ su - ansible
$ cd ~/ansible
$ git clone https://github.com/ryandaniels/ansible-role-create-users.git roles/create-users</code></pre>
<p>Or, you can use Ansible Galaxy to install this role:</p>
<pre><code>$ su - ansible
$ ansible-galaxy install ryandaniels.create_users</code></pre>
<h3>Setup Ansible Vault</h3>
<p>If you don&#8217;t already have <a href="https://docs.ansible.com/ansible/latest/vault.html" target="_blank" rel="noopener noreferrer">Ansible Vault</a> configured, you will need to set it up now. Vault uses AES encryption to store your sensitive information. And we need Ansible Vault to encrypt our user configuration file since we don&#8217;t want to be exposing even a hashed password into source control.</p>
<p>First, (if using git), make sure to update your .gitignore file so your Vault password isn&#8217;t saved to your source control. And also add the secret file we will be creating later:</p>
<pre><code>$ vi .gitignore
.vaultpass
secret
*.secret</code></pre>
<p>Next, create a password for your Ansible Vault and save it in your Password Manager (like <a href="https://keepassxc.org/" target="_blank" rel="noopener noreferrer">KeePassXC</a>). Then create the .vaultpass file, add the Vault password, and fix the permissions:</p>
<pre><code>$ vi .vaultpass
#Enter password here

$ chmod 600 .vaultpass</code></pre>
<p>Also you need to update the Ansible config file to reference where the Vault file is located:</p>
<pre><code>$ vi ansible.cfg
[defaults]
vault_password_file = ./.vaultpass
</code></pre>
<h3>Create Ansible Playbook</h3>
<p>Next, create the Playbook file:</p>
<pre><code>$ vi create-users.yml
---
- hosts: '{{inventory}}'
  vars_files:
    - vars/lab_users.secret
  become: yes
  roles:
  - create-users</code></pre>
<h3>Create configuration for user management</h3>
<p>Next, add your users into a configuration file. The below is only an example, don&#8217;t use it in your user management configuration file. Also, make sure the filename matches a .gitignore entry. In this case it will match &#8220;*.secret&#8221;.<br />
Use the special Ansible command to create the encrypted Ansible Vault file:</p>
<pre><code>$ mkdir -p vars
$ ansible-vault create vars/lab_users.secret
---
users:
  - username: alice
    password: $6$/y5RGZnFaD3f$96xVdOAnldEtSxivDY02h.DwPTrJgGQl8/MTRRrFAwKTYbFymeKH/1Rxd3k.RQfpgebM6amLK3xAaycybdc.60
    update_password: on_create
    comment: Test User 100
    shell: /bin/bash
    ssh_key: |
      ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx8crAHG/a9QBD4zO0ZHIjdRXy+ySKviXVCMIJ3/NMIAAzDyIsPKToUJmIApHHHF1/hBllqzBSkPEMwgFbXjyqTeVPHF8V0iq41n0kgbulJG alice@laptop
      ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx8crAHG/a9QBD4zO0ZHIjdRXy+ySKviXVCMIxxxxxxxxxxxxxxxxxxJmIApHHHF1/hBllqzBSkPEMwgFbXjyqTeVPHF8V0iq41n0kgbulJG alice@server1
    exclusive_ssh_key: yes
    use_sudo: no
    use_sudo_nopass: no
    user_state: present
    servers:
      - webserver
      - database
      - monitoring

  - username: bob
    password: $6$XEnyI5UYSw$Rlc6tXtECtqdJ3uFitrbBlec1/8Fx2obfgFST419ntJqaX8sfPQ9xR7vj7dGhQsfX8zcSX3tumzR7/vwlIH6p/
    ssh_key: AAAAB3NzaC1yc2EAAAADAQABAAACAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx8crAHG/a9QBD4zO0ZHIjdRXy+ySKviXVCMIxxxxxxxxxxxxxxxxxxJmIApHHHF1/hBllqbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbulJG bob@laptop
    use_sudo: no
    user_state: lock
    servers:
      - webserver
      - database</code></pre>
<p>In the above example, there are two users. Users: alice and bob. If you are familiar with user management on Linux, then most of these settings are self explanatory. For example, both Alice and Bob have a hashed password and ssh keys. Alice actually has two ssh keys configured. But Bob&#8217;s account is locked so he can&#8217;t log in.</p>
<p>The interesting part is the list of &#8220;servers&#8221; in the configuration. These are groups defined in your Ansible hosts file. So you can give certain users access to a specific group of servers, depending on the user&#8217;s role.</p>
<p>Important note: Be careful with the <code>update_password</code> setting. When set to <code>always</code>, the user&#8217;s password will be changed to what is defined in <code>password</code>. This might not be what they wanted if they&#8217;ve manually changed their password so it&#8217;s usually safer to use <code>on_create</code>.</p>
<p>For details about all the different settings, see the <a href="https://github.com/ryandaniels/ansible-role-create-users/blob/master/README.md#user-settings" target="_blank" rel="noopener noreferrer">README</a> on GitHub.</p>
<p>Going forward, to update the file, instead of the &#8220;create&#8221; command line option, use &#8220;edit&#8221;:</p>
<pre><code>$ ansible-vault edit vars/lab_users.secret</code></pre>
<p>And don&#8217;t forget to save this into your source control (git).</p>
<h3>Run the Ansible Playbook</h3>
<pre><code>$ ansible-playbook create-users.yml --extra-vars "inventory=all-dev" -i hosts-dev</code></pre>
<p>Marvel at the output generated by Ansible. All these users are created, updated, or locked, but only if something needed to change since Ansible is idempotent.</p>
<h3>Bonus: Add this in Jenkins</h3>
<p>If you also use Jenkins for your CI/CD pipeline, you can add this Ansible Playbook into Jenkins.</p>
<p>You just need to setup Jenkins to use Ansible and Ansible Vault. And there is a great Jenkins Plugin to help. Just follow this guide to use <a href="https://ryandaniels.ca/blog/ansible-vault-jenkins/">Ansible Vault with Jenkins</a>. Keep in mind that updating the user configuration file is only possible from the command line, since it&#8217;s encrypted using Ansible Vault.</p>
<h2>Conclusion</h2>
<p>In conclusion, there are many options for user management on Linux servers. From enterprise solutions like Red Hat IDM. Or, using the upstream open source software IDM uses directly, FreeIPA. If you decide to use Ansible, then the above Ansible role will get the job done. And you can also add it into Jenkins.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-user-management/">User Management with Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1251</post-id>	</item>
		<item>
		<title>Getting Started with Ansible on Ubuntu or CentOS</title>
		<link>https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Tue, 06 Feb 2018 13:46:59 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1133</guid>

					<description><![CDATA[<p><a href="https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/"><img class="alignleft size-thumbnail wp-image-1170" src="https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo-e1517962271957-150x150.png" alt="Setup Ansible - Getting Started with Ansible" width="150" height="150" /></a> This is a guide to getting started with Ansible. By the end of this guide, you will be up and running with Ansible.<br />
Included is an Ansible role that will create a user which is used by Ansible to connect to your remote servers. Let's go! After installing Ansible, you will need to setup Ansible by following these steps.</p>
<p>The post <a href="https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/">Getting Started with Ansible on Ubuntu or CentOS</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This is a guide to getting started with Ansible. By the end of this guide, you will be up and running with Ansible!<br />
Included is an Ansible role that will create a user which is used by Ansible to connect to your remote servers. After installing Ansible, you will need to setup Ansible by following these steps since there is a bit more to it than you may think.</p>
<p><span id="more-1133"></span></p>
<h2><a id="what-is-ansible" href="#what-is-ansible"></a>What is Ansible?</h2>
<p><img decoding="async" class="alignright wp-image-1170 size-medium" src="https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo-244x300.png" alt="Setup Ansible - Getting Started with Ansible" width="244" height="300" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo-244x300.png 244w, https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo.png 256w" sizes="(max-width: 244px) 100vw, 244px" /></p>
<p>First of all, Ansible is amazing at IT automation. Ansible is a command line IT automation solution that can deploy configuration changes, software, and perform many other tasks all automatically. To get more information about what Ansible is, check out the <a href="http://docs.ansible.com/ansible/latest/index.html" target="_blank" rel="noopener noreferrer">Ansible documentation</a>.</p>
<p>Ansible is modular, so you can create groups of tasks, called roles. And then you can group the roles together to all run sequentially inside of a playbook.<br />
An <a href="http://docs.ansible.com/ansible/latest/playbooks.html" target="_blank" rel="noopener noreferrer">Ansible Playbook</a> can run against one or multiple servers, depending how you reference the servers in your Playbook, and also depending on how you group the servers in your <a href="http://docs.ansible.com/intro_inventory.html" target="_blank" rel="noopener noreferrer">Ansible inventory</a> file.</p>
<h2>Setup Ansible</h2>
<p>Ansible uses ssh to connect to all of your remote servers to perform the tasks you define. After you install Ansible, it&#8217;s a good idea to create a user for Ansible to use. You need to do this on all servers that Ansible will be managing. Instead of doing that manually, use Ansible!</p>
<h3>Install Ansible</h3>
<p>First, let&#8217;s install Ansible on the local machine.</p>
<p>On Ubuntu 16.04 install Ansible using apt-get:</p>
<pre><code>$ sudo apt-get update &amp;&amp; sudo apt-get install ansible</code></pre>
<p>On CentOS/RHEL 7 install Ansible using yum:</p>
<pre><code>$ sudo yum install ansible</code></pre>
<h3>Ansible local user and Ansible directory</h3>
<p>On the local (control) server, all of the below Ansible commands are executed as the local Ansible user.</p>
<p>Create the user if it doesn&#8217;t exist and then run every command from now on as the Ansible user:</p>
<pre><code>$ sudo useradd ansible

$ su - ansible</code></pre>
<p>Create and go into the Ansible base directory:</p>
<pre><code>$ mkdir ~/ansible
$ cd ~/ansible</code></pre>
<h3>Ansible Inventory</h3>
<p>Ansible uses an <a href="http://docs.ansible.com/intro_inventory.html" target="_blank" rel="noopener noreferrer">inventory</a> file which contains all the remote servers you will be connecting to. This is the first thing you need do in order to setup Ansible.</p>
<p>An example of a simple inventory file using a group name &#8220;ubuntu-dev&#8221; with the hostname of two remote servers:</p>
<pre><code>$ cat &gt; ~/ansible/hosts &lt;&lt; 'EOF'
[ubuntu-dev]
ubuntu-web
ubuntu-db
EOF</code></pre>
<h3>Create SSH Key</h3>
<p>Create an ssh key for the local Ansible user using RSA keys, since that is still more common than ed25519:</p>
<pre><code>$ ssh-keygen -t rsa -b 4096</code></pre>
<h3>SSH to all remote servers</h3>
<p>You need to ssh to the servers beforehand, since you need to have the ssh host keys in your known_hosts file for <a href="https://www.symantec.com/connect/articles/ssh-host-key-protection" target="_blank" rel="noopener noreferrer">security reasons</a>. Therefore, make sure you are connecting to the expected servers.</p>
<p>You could do this manually, but instead use Ansible to ssh to all the servers in your Ansible inventory file to populate the known_hosts file. Do not run this in a production environment and make sure you are connecting to the expected servers by verifying the ssh key fingerprints.</p>
<pre><code>$ ansible all -m ping --extra-vars "ansible_ssh_common_args='-o StrictHostKeyChecking=no'" -i hosts</code></pre>
<p>This command is using the Ansible ping module (-m ping) to ssh to <strong>all</strong> servers in your inventory file (-i hosts), and this will create entries in the ~/.ssh/known_hosts file.</p>
<h3>Install Ansible required packages</h3>
<p>Next, you need to install some packages that <a href="https://docs.ansible.com/ansible/latest/intro_installation.html#managed-node-requirements" target="_blank" rel="noopener noreferrer">Ansible requires on the remote servers</a>. Currently, Ansible uses Python 2 by default. So your remote servers will need to have Python 2 installed.</p>
<p>Use Ansible to install Python 2 on a remote Ubuntu server:</p>
<pre><code>$ ansible ubuntu-dev -m raw -a "apt-get update &amp;&amp; apt-get install -y python-minimal python-simplejson" -i hosts</code></pre>
<p>If using CentOS 7 or RHEL 7 you don&#8217;t need to install Python 2 since it is already installed by default.</p>
<p>But, if using an old version like CentOS 5 or RHEL 5, you will need to <a href="https://github.com/ryandaniels/ansible-role-create-user-ansible#rhel5" target="_blank" rel="noopener noreferrer">run these commands</a>. And if using SELinux with CentOS 5 or RHEL 5, <a href="https://github.com/ryandaniels/ansible-role-create-user-ansible#selinux" target="_blank" rel="noopener noreferrer">run these commands</a> to allow the Ansible copy/file/template modules.</p>
<h3>Create Ansible user on remote servers</h3>
<p>You can use my Ansible role on <a href="https://github.com/ryandaniels/ansible-role-create-user-ansible" target="_blank" rel="noopener noreferrer">GitHub</a> called create-user-ansible to have Ansible create its own user.</p>
<p>This new user will then use password-less sudo by default. But you can change this with a <a href="https://github.com/ryandaniels/ansible-role-create-user-ansible#default-settings" target="_blank" rel="noopener noreferrer">variable</a> if you want to be prompted for a password every time you run Ansible.</p>
<p>Clone the git repository:</p>
<pre><code>$ git clone https://github.com/ryandaniels/ansible-role-create-user-ansible.git ~/ansible/roles/create-user-ansible</code></pre>
<p>Create the Ansible Playbook file:</p>
<pre><code>$ cat &gt; ~/ansible/create-user-ansible.yml &lt;&lt; 'EOF'
---
- hosts: '{{inventory}}'
  become: yes
  roles:
  - create-user-ansible
EOF
</code></pre>
<p>Now the most important step, run the Ansible playbook.</p>
<p>This assumes you have a way to log in via ssh to your servers. (How else would you remotely connect?)<br />
Change &#8220;remote_existing_user&#8221; to the username you already have on your servers.<br />
Change &#8220;username&#8221; to your local Ansible username. This should be the same user as the local Ansible user since this makes things easier.</p>
<p>As a result, this will create a new user on all your servers named: ansible<br />
More options are available, see the <a href="https://github.com/ryandaniels/ansible-role-create-user-ansible" target="_blank" rel="noopener noreferrer">README on GitHub</a>.</p>
<p>If your existing user uses a password for ssh authentication and does not use password-less sudo:</p>
<pre><code>$ ansible-playbook create-user-ansible.yml --ask-pass --become --become-method=su --ask-become-pass --extra-vars "inventory=all ansible_ssh_user=remote_existing_user username=ansible" -i hosts
</code></pre>
<p>If your existing user uses password-less ssh using ssh keys and no password for sudo:</p>
<pre><code>$ ansible-playbook create-user-ansible.yml --become --become-method=sudo --extra-vars "inventory=all ansible_ssh_user=remote_existing_user username=ansible" -i hosts</code></pre>
<h2>Conclusion</h2>
<p>In conclusion, now you have an Ansible user created on all of your servers. You have installed and setup Ansible, and this is the first step! Next, write your own <a href="http://docs.ansible.com/ansible/latest/playbooks.html" target="_blank" rel="noopener noreferrer">Playbook</a>. Or use one of mine to <a href="https://ryandaniels.ca/blog/ansible-update-ubuntu-centos-redhat/">update all of your Ubuntu or CentOS servers and automatically reboot them</a>.</p>
<p>This guide is a quick way to get started with Ansible. Keep in mind, Ansible can be complex. You should plan out how you want to setup Ansible&#8217;s directory structure by following their <a href="https://docs.ansible.com/ansible/latest/playbooks_best_practices.html#alternative-directory-layout" target="_blank" rel="noopener noreferrer">best practices</a>. And take some time to read their <a href="http://docs.ansible.com/ansible/latest/index.html" target="_blank" rel="noopener noreferrer">documentation</a>!</p>
<p>The post <a href="https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/">Getting Started with Ansible on Ubuntu or CentOS</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1133</post-id>	</item>
		<item>
		<title>Using Ansible to Update Ubuntu, CentOS, and Redhat</title>
		<link>https://ryandaniels.ca/blog/ansible-update-ubuntu-centos-redhat/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Mon, 15 Jan 2018 13:39:43 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=993</guid>

					<description><![CDATA[<p>Keeping your software updated is important. You get the newest features, and more importantly, you also get the latest security fixes. This Ansible role can automate the updates to your Ubuntu, CentOS, and Redhat servers with the latest packages, reboot if needed and wait for the server to start up.</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-update-ubuntu-centos-redhat/">Using Ansible to Update Ubuntu, CentOS, and Redhat</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Keeping your software updated is important. You get the newest features, and more importantly, you also get the latest security fixes. Ansible can help you to automate the updating of your software.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1010 size-full" title="Spectre and Meltdown security vulnerabilities. Update Ubuntu, CentOS 7, Redhat 7 using Ansible" src="https://ryandaniels.ca/wp-content/uploads/2018/01/spectre_meltdown.png" alt="Spectre and Meltdown security vulnerabilities. Update Ubuntu, CentOS 7, Redhat 7 using Ansible" width="509" height="326" srcset="https://ryandaniels.ca/wp-content/uploads/2018/01/spectre_meltdown.png 509w, https://ryandaniels.ca/wp-content/uploads/2018/01/spectre_meltdown-300x192.png 300w" sizes="auto, (max-width: 509px) 100vw, 509px" /></p>
<p>With all the latest news about the <a href="https://spectreattack.com/" target="_blank" rel="noopener noreferrer">Spectre</a> and <a href="https://meltdownattack.com/" target="_blank" rel="noopener noreferrer">Meltdown</a> security vulnerabilities it is important to keep the software updated on all your devices. If you are a desktop user, update your OS now*. If you maintain Linux servers, update those now* as well.<br />
The below information can help you use Ansible to update all of your Ubuntu, CentOS, and Redhat servers.</p>
<p><span id="more-993"></span></p>
<p><strong>* Disclaimer</strong>: Test any updates thoroughly before upgrading your production environments since an update could introduce performance impacts or issues. I am not responsible if you break anything!</p>
<h2><a id="what-is-ansible" href="#what-is-ansible"></a>What is Ansible?</h2>
<p>First of all, Ansible is amazing at IT automation. Ansible is a command line IT automation solution that can deploy configuration changes, software, and perform many other tasks all automatically. However, you should be extra cautious when running any type of automation for server updates. To get more information about what Ansible is, check out the <a href="http://docs.ansible.com/ansible/latest/index.html" target="_blank" rel="noopener noreferrer">Ansible documentation</a>.</p>
<p>Ansible is modular, so you can create groups of tasks, called roles. And then you can group the roles together to all run sequentially inside of a playbook.<br />
An Ansible playbook can run against one or multiple servers, depending how you reference the servers in your playbook, and also depending on how you group the servers in your <a href="http://docs.ansible.com/intro_inventory.html" target="_blank" rel="noopener noreferrer">Ansible inventory</a> file.</p>
<h2><a id="what-the-ansible-update-role-does" href="#what-the-ansible-update-role-does"></a>What the Ansible server update role does</h2>
<p>This is an Ansible role to update your servers with the latest packages, reboot the server if needed, and wait for the server to start up.<br />
You can also exclude packages from the update, update only specified packages, or install only specified packages.</p>
<p>A reboot of the server is only be performed if the reboot flag is set (which is enabled by default), and if the kernel was updated or another package indicates to the OS that a reboot is needed.</p>
<p>Also, it seems obvious, but just in case.. Be sure to stop your applications before updating and rebooting your server, and then start your applications again after.<br />
You can add more roles after this role to continue installing and configuring your server.</p>
<p>Tested on Ubuntu 16.04, Ubuntu 18.04, CentOS 7.x, and Redhat Enterprise Linux (RHEL) 7.x servers.</p>
<p><a href="https://github.com/ryandaniels/ansible-role-server-update-reboot" target="_blank" rel="noopener noreferrer">You can find this Ansible role on Github</a> or <a href="https://galaxy.ansible.com/ryandaniels/server_update_reboot" target="_blank" rel="noopener noreferrer">Ansible Galaxy</a>. Check back for any updates on Github, and also for more information about the variables used in this Ansible role.</p>
<h2><a id="spectre-meltdown-mitigation" href="#spectre-meltdown-mitigation"></a>Bonus &#8211; Spectre and Meltdown mitigation</h2>
<p>As an extra bonus, this Ansible role can also help you mitigate the recent security vulnerabilities called Spectre and Meltdown (once updates are available for your operating system of course).</p>
<p>More information about how to mitigate Spectre and Meltdown (CVE-2017-5754, CVE-2017-5753, CVE-2017-5715) is available for <a href="https://wiki.ubuntu.com/SecurityTeam/KnowledgeBase/SpectreAndMeltdown" target="_blank" rel="noopener noreferrer">Ubuntu</a> and <a href="https://access.redhat.com/security/vulnerabilities/speculativeexecution" target="_blank" rel="noopener noreferrer">CentOS/Redhat</a>. When new mitigations become available you will need to patch your servers again. And with Ansible it can be <em>less</em> painful.</p>
<p>To begin updating, continue reading. You can also jump directly to the example commands which can be used to <a href="#spectre-meltdown-mitigation-example">mitigate Spectre and Meltdown</a> if that is all you want to do. But, keep in mind it is usually better to keep all of the packages updated*.</p>
<h2><a id="using-ansible-to-update-ubuntu-centos-redhat-7" href="#using-ansible-to-update-ubuntu-centos-redhat-7"></a>Using Ansible to update Ubuntu and CentOS/Redhat 7</h2>
<p>This assumes you have <a href="http://docs.ansible.com/intro_installation.html" target="_blank" rel="noopener noreferrer">Ansible</a> and <a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git" target="_blank" rel="noopener noreferrer">git</a> installed.<br />
In addition, you also need to follow a few steps before running the playbook. If you have already done this, you can <a href="#install-ansible-role-update-server">skip ahead to installing the role</a>.</p>
<h3><a id="prerequisites" href="#prerequisites"></a>Prerequisites</h3>
<p>Before you begin, make sure you have your <a href="http://docs.ansible.com/ansible/latest/intro_inventory.html#splitting-out-host-and-group-specific-data" target="_blank" rel="noopener noreferrer">Ansible &#8220;group_vars&#8221;</a> setup for the Ansible hosts you are running this playbook against. &#8220;centos-dev&#8221; is the host group in the example below.</p>
<pre><code>$ vi ./group_vars/centos-dev/proxy.yml</code></pre>
<p>If you are behind a corporate firewall and use a proxy, add:</p>
<pre><code>proxy_env:
  http_proxy: http://my.internal.proxy:80/
  https_proxy: https://my.internal.proxy:80/</code></pre>
<p>If not using a proxy, add:</p>
<pre><code>proxy_env: []</code></pre>
<h3><a id="install-ansible-role-update-server" href="#install-ansible-role-update-server"></a>Install Ansible role to update the server</h3>
<p>To install the Ansible role that handles updating your server(s), go into the directory you have your Ansible playbooks. Or, if you don&#8217;t have any existing playbooks, then create a new directory for the Ansible role and playbook.</p>
<p>Next, clone my Github repository with the Ansible role.</p>
<pre><code>$ cd ~/ansible
$ git clone https://github.com/ryandaniels/ansible-role-server-update-reboot.git roles/server-update-reboot</code></pre>
<p>Or, you can use Ansible Galaxy to install this role:</p>
<pre><code>$ cd ~/ansible
$ ansible-galaxy install ryandaniels.server_update_reboot</code></pre>
<h3><a id="create-ansible-playbook" href="#create-ansible-playbook"></a>Create your Ansible Playbook</h3>
<p>Now, create your Ansible Playbook file for the server update role. You can also add other roles to run before or after.</p>
<pre><code>$ vi server-update-reboot.yml

---
- hosts: '{{inventory}}'
max_fail_percentage: 0
serial: 1
become: yes
roles:
# - stop-applications
- server-update-reboot
# - server-config-xyz
#  - start-applications</code></pre>
<p><strong>Tip</strong>: The above will update one server at a time (using max_fail_percentage and serial). If you want to update everything at once you can comment those two lines out. Be careful with this since you could update and reboot all your servers at once!</p>
<h3><a id="update-servers-run-playbook" href="#update-servers-run-playbook"></a>Update your servers &#8211; Run the Playbook</h3>
<p>Finally, the last step is to run the Ansible Playbook. Below are examples for various scenarios.</p>
<p><strong>Note: It is important to understand what will happen. This will reboot your server by default!</strong></p>
<h4><a id="update-servers-example-redhat-centos-ubuntu-update-all" href="#update-servers-example-redhat-centos-ubuntu-update-all"></a>Example for Ubuntu &amp; Redhat/CentOS to update all packages</h4>
<p>Use all defaults for the role to: update packages, reboot server if needed, and wait for the server to start up.</p>
<pre><code>ansible-playbook server-update-reboot.yml --extra-vars "inventory=all-dev" -i hosts-dev</code></pre>
<p>Below is the same as above, but now the server is <strong>not</strong> rebooted, even when a reboot is needed. In this example the extra variable &#8220;reboot_default&#8221; is used on the command line to change the reboot variable to false.</p>
<pre><code>ansible-playbook server-update-reboot.yml --extra-vars "inventory=all-dev reboot_default=false" -i hosts-dev</code></pre>
<p>Keep in mind that a server reboot may be necessary to complete the updates. For example, if a kernel update was applied.</p>
<h4><a id="update-servers-example-redhat-centos-limit" href="#update-servers-example-redhat-centos-limit"></a>Example for Redhat/CentOS to limit packages being updated</h4>
<p>Update all packages except package(s) specified:</p>
<pre><code>ansible-playbook server-update-reboot.yml --extra-vars 'inventory=centos-dev server_update_yum_exclude_pkgs="mysql*, bash, openssh*"' -i hosts-dev</code></pre>
<p>Update (or install) only specific package(s):</p>
<pre><code>ansible-playbook server-update-reboot.yml --extra-vars "inventory=centos-dev server_update_yum_install_pkgs='kernel-*, iwl*firmware, microcode_ctl, dracut'" -i hosts-dev</code></pre>
<h4><a id="update-servers-example-ubuntu-limit" href="#update-servers-example-ubuntu-limit"></a>Example for Ubuntu to limit packages being updated</h4>
<p>Update all packages except package(s) specified:</p>
<pre><code>ansible-playbook server-update-reboot.yml --extra-vars 'inventory=ubuntu-dev server_update_apt_exclude_default=true' --extra-vars '{"server_update_apt_exclude_pkgs": [bash, openssl, ^mysql*, ^openssh*]}' -i hosts-dev</code></pre>
<p>Update only specific package(s):</p>
<pre><code>ansible-playbook server-update-reboot.yml --extra-vars "inventory=ubuntu-dev server_update_apt_default=update_specific" --extra-vars "{'server_update_apt_install_pkgs': [linux-firmware, linux-generic, linux-headers-generic, linux-image-generic, intel-microcode, openssh*]}" -i hosts-dev</code></pre>
<p>Install only specific package(s):</p>
<pre><code>ansible-playbook server-update-reboot.yml --extra-vars "inventory=ubuntu-dev server_update_apt_default=install" --extra-vars "{'server_update_apt_install_pkgs': [bash, openssh-server]}" -i hosts-dev</code></pre>
<p>Be careful with wildcards since they can install more than you might want.</p>
<h3><a id="spectre-meltdown-mitigation-example" href="#spectre-meltdown-mitigation-example"></a>Examples for Spectre and Meltdown Mitigation</h3>
<p>To update Ubuntu 16.04, Redhat 7, and CentOS 7 with only the available Spectre and Meltdown mitigations use the below examples.</p>
<p>Keep in mind it&#8217;s usually better to <a href="#update-servers-example-redhat-centos-ubuntu-update-all">keep all of the packages up to date</a>.</p>
<h4><a id="spectre-meltdown-mitigation-redhat-centos-7" href="#spectre-meltdown-mitigation-redhat-centos-7"></a>For Redhat/CentOS 7 (Spectre/Meltdown Mitigation)</h4>
<pre><code>ansible-playbook server-update-reboot.yml --extra-vars "inventory=centos-dev server_update_yum_install_pkgs='kernel-*, iwl*firmware, microcode_ctl, dracut'" -i hosts-dev</code></pre>
<h4><a id="spectre-meltdown-mitigation-ubuntu-1604" href="#spectre-meltdown-mitigation-ubuntu-1604"></a>For Ubuntu 16.04 (Spectre/Meltdown Mitigation)</h4>
<pre><code>ansible-playbook server-update-reboot.yml --extra-vars "inventory=ubuntu-dev server_update_apt_default=update_specific" --extra-vars "{'server_update_apt_install_pkgs': [linux-firmware, linux-generic, linux-headers-generic, linux-image-generic, intel-microcode]}" -i hosts-dev</code></pre>
<h2><a id="conclusion" href="#conclusion"></a>Conclusion</h2>
<p>Automation using a tool like Ansible is very powerful. With Ansible&#8217;s help you can update all of your Ubuntu, CentOS, and Redhat servers quickly. Finally, with all of the recent issues surrounding Spectre and Meltdown, the Ansible server update role can help you keep everything updated and more secure.</p>
<p>Now that your servers are patched, you can look at other Ansible roles to help you install and configure software. If you have your own VPS, check out the <a href="https://ryandaniels.ca/blog/openvpn-ad-blocking/">Ansible role to setup OpenVPN with ad blocking</a>.</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-update-ubuntu-centos-redhat/">Using Ansible to Update Ubuntu, CentOS, and Redhat</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">993</post-id>	</item>
	</channel>
</rss>
