Category: ansible

Getting Jenkins to deploy with ansible using SSH Agent Forwarding

Your CI/CD tool needs access to code and server, for linting, testing and deploying.
Setup up access on the various devices in a secure manner can be very time consuming. It is important to make use of available technology to make our lives easier.

Jenkins needs access

You will have created credentials for Jenkins – by creating a SSH key pair for your jenkins user. Ensure that that public key have access to the code on your version control platform (as a deploy key).

Now jenkins will be able to get your code and run various tests on it. The problem now is deployment.


Use Jenkins’s SSH credentials to Deploy

We are using ansible to deploy (from the jenkins box). So now jenkins needs access to wherever you are deploying the code to. You would do an ssh-copy-id to get it there.

But there is another problem, when ansible runs the git module to clone the repo you will get an error that the user does not have access.

Correct, the user on the box you are deploying to does not have access to the code. Now you could add that box as another deploy key but now when scaling out to many boxes you will have a hell of alot of ssh credentials to manage.

The best thing to do is use the jenkins user’s cerentials that log into your target box to get the code. This is done with SSH Agent forwarding.

The first thing we will need is the  jenkins SSH agent plugin.

Then enable the SSH agent for your job:



Then install the Jenkins ansible plugin and configure it.

Finally you need to tell ansible to use SSH Agent forwarding, otherwise it just won’t do it:

mkdir /etc/ansible
vi /etc/ansiible/ansible.cfg

Add the following config there:

host_key_checking = False

ssh_args = -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s

Of course, it is better to ensure host_key_checking is done.

Now everything should work.

Source: SSH Agent Forwarding with Ansible

How to install Ubuntu 16.04 and Automatically Install all my apps

How to install Ubuntu 16.04 and Automatically Install all my apps

I’m assuming this gets searched quite a lot. It is one thing installing ubuntu, but another hugely time consuming gig installing all the old applications that you like. Couple that with your configurations of .bashrc, application configs, editor configs and logins for apps and it becomes a seemingly impossible task.

But it’s not it can be done with an awesome tools known as ansible which will become known to you in due time. First off lets install it.

Remember this tutorial is just for a ffresh install of the Desktop ubuntu version, although the ansible script can be modified for a server. If you just want to upgrade your ubuntu 14.04 LTS server to Ubuntu 16,.04 check this out

Installing Ubuntu 16.04

  1. Download the desktop version of Ubuntu 16.04, it is a .iso.
  2. Get an empty USB Flash drive (2 gb or more) or clear an old one with ubuntu (Or use gparted it’s the best, see below)
  3. Get a PC ready either for a dual boot (Windows and Ubuntu) or just Ubuntu. I think the .iso we just downloaded has gparted – a utility to partition space to install operating systems – installed. Otherwise get gparted here. Clear enough free space for ubuntu (20gb should be ok) with gparted.
  4. On an ubuntu machine: Windows key -> Search for Startup disk Creator -> Open it -> Make a Startup disk with the ubuntu .iso Alternatively if you are on windows you can use Unetbootin to Install the iso onto a USB
  5. Get the pc you have cleared to install ubuntu on and plug in the startup/ bootable usb, make sure to select the drive of the USB to boot from
  6. Now say install ubuntu not try ubuntu without installing Unless you just want to try it
  7. It will prompt for your language choice, but this is a good time to connect to your wifi in the top right.
  8. Select your language and continue, then depending on your preference choose Download updates while installing ubuntu and Install third-party software for graphics and Wi-Fi hardware, Flash,MP3 and other Media
  9. Continue and wait a while…
  10. It will then ask the installation type. Make your choice depending on if you want to dual boot and just want the new ubuntu or something else. You will need to make some swap space available for memory if you choose something else, use this guide on the manual ubuntu partitioning. (I changedto install alongside, because I got an error with the manual method, I also didn’t connect to the wifi)
  11. Next select your timezone/city then your keyboard layout
  12. Next your name (this is used as the name of your home folder /home/surfer190 so make sure it is lower case and simple. Choose a password and continue. You can enrypt your home folder if you aren’t the only user on the pc.
  13. Install then completes, Woohoo fresh install

Customisation and Automatically Install all my apps

First thing I noticed was the unnatural scrolling direction of the two-finger scroll on the touchpad.