<?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: Jenkins - Ryan Daniels</title>
	<atom:link href="https://ryandaniels.ca/blog/tag/jenkins/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Fri, 13 Dec 2019 02:44:25 +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: Jenkins - Ryan Daniels</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">22628916</site>	<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>Ansible Vault with Jenkins</title>
		<link>https://ryandaniels.ca/blog/ansible-vault-jenkins/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Tue, 13 Feb 2018 13:26:59 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Jenkins]]></category>
		<category><![CDATA[Security]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1253</guid>

					<description><![CDATA[<p>Ansible can use encrypted files, using a feature called Ansible Vault. This is great for sensitive information that you don't want to store as a normal text file since you are able to encrypt this data in your souce control.</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-vault-jenkins/">Ansible Vault with Jenkins</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Ansible can use encrypted files, using a feature called Ansible Vault. This is great for sensitive information that you don&#8217;t want to store as a normal text file since you are able to encrypt this data in your source control.</p>
<p><span id="more-1253"></span></p>
<p>If you are new to Ansible, read the <a href="https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/" target="_blank" rel="noopener noreferrer">getting started with Ansible</a> post first.</p>
<h2>Why use Ansible Vault?</h2>
<p>You want to use Ansible Vault when you need to use sensitive data with Ansible, like a login and password, or SSH keys. Instead of storing this sensitive information in plain text, where anyone can read it when you save your <a href="http://docs.ansible.com/ansible/latest/playbooks_vault.html" target="_blank" rel="noopener noreferrer">Ansible Playbooks</a> to your source control (like git), Vault uses an AES cypher to encrypt your data.</p>
<p>For more details, read the <a href="http://docs.ansible.com/ansible/latest/vault.html" target="_blank" rel="noopener noreferrer">documentation</a>.</p>
<h2>Ansible Vault with Jenkins</h2>
<p><a href="https://jenkins.io/" target="_blank" rel="noopener noreferrer">Jenkins</a> is software for Continuous Integration and Continuous Delivery. You can add plugins to Jenkins to extend its base features. And one handy plugin allows you to use Ansible with Jenkins.</p>
<p>Recently, the Ansible Plugin for Jenkins was updated to version 0.8.0, and as a result it now works seamlessly with Ansible Vault.</p>
<h2>Install Ansible plugins for Jenkins</h2>
<p>The first thing you need to install is the <a href="https://plugins.jenkins.io/ansible" target="_blank" rel="noopener noreferrer">Ansible plugin</a> for Jenkins.<br />
Also, install the dependent plugin called <a href="https://plugins.jenkins.io/credentials-binding" target="_blank" rel="noopener noreferrer">Credentials Binding</a>.</p>
<p>One thing to note is you can only read from encrypted Ansible Vault encrypted files. You cannot create or modify them using the Jenkins Ansible plugin. So you will still need to use the CLI to modify your encrypted files.</p>
<h2>Add Vault password to Jenkins</h2>
<p>The simplest way to use Ansible Vault with Jenkins is to add your Vault password into a Jenkins Credential. Then you can bind the credential to an environment variable, or use it directly as a &#8220;Vault Credential&#8221;.</p>
<p>Configure your Jenkins freestyle project that uses an Ansible Playbook. If you have the newest version of the Ansible plugin, under the &#8220;Build&#8221; section you will now see an option for &#8220;Vault Credentials&#8221; since this is a new feature.</p>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-1280" src="https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials.png" alt="ansible vault jenkins credentials" width="643" height="289" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials.png 643w, https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials-300x135.png 300w" sizes="(max-width: 643px) 100vw, 643px" /></p>
<p>Add a new Jenkins Credential as &#8220;Secret text&#8221;, and enter your Ansible Vault encryption password.</p>
<p><img decoding="async" class="alignnone size-full wp-image-1281" src="https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials_new.png" alt="ansible vault jenkins new credentials" width="515" height="428" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials_new.png 515w, https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials_new-300x249.png 300w" sizes="(max-width: 515px) 100vw, 515px" /></p>
<p>Next, select the new Vault Credentials and you are ready to use your encrypted files in your Jenkins build job from your Ansible Playbooks.</p>
<h2>Conclusion</h2>
<p>In conclusion, you are now using Ansible Vault encrypted files automatically inside of your Jenkins build jobs. This helps you to keep your sensitive data secured in your source control. And Jenkins is helping you to deploy your Ansible Playbooks, while seamlessly decrypting your files.</p>
<p>Next, you can add a job to Jenkins that requires Ansible Vault. If you want to use Ansible for user management on Linux servers, check out the guide for <a href="https://ryandaniels.ca/blog/ansible-user-management/">User Management with Ansible</a>.</p>
<p>&nbsp;</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-vault-jenkins/">Ansible Vault with Jenkins</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1253</post-id>	</item>
	</channel>
</rss>
