3

Summary

I have an ansible playbook that does something awesome. This works because I've setup ssh to allow me to spread the awesomeness on my servers. I wanted to setup jenkins to deliver the awesomeness automatically at the conclusion of a successful build.

This fails because jenkins does not have the same ssh capability I have. How can I achieve continuous delivery of my app using ansible and jenkins?

Option: authorize-project-plugin

https://wiki.jenkins-ci.org/display/JENKINS/Authorize+Project+plugin

I installed this plugin so that if I trigger the job it would run as me.

  • Enabled 'Run as User who Triggered Build' under Configure Global Security
  • Enabled 'Configure Build Authorization' and 'Run as User who Triggered Build' in my project
  • Added Build step to run shell command whoami

The console output says:

Started by user my name

Running as my name

Building in workspace my path

+ whoami

jenkins

I would have expected my username there, not jenkins.

UPDATE: I did learn that this plugin is intended for jenkins application authorizations, not system authentication. The jenkins user would need to sudo user as part of any script execution.

Option: give jenkins user NOPASSWD sudo

The jenkins acct is a system account, no tty by default. I could make it a full user account, grant sudo access, etc. but that seems like a bigger security issue than impersonating a user account.

Option: docker

Option: ansible tower


  • jenkins version 1.617
  • authorize project plugin version 1.1.0
Community
  • 1
  • 1
j12y
  • 2,112
  • 3
  • 17
  • 22

1 Answers1

3

In Jenkins I usually checkout my ansible playbook folder and run it with jenkins shell command.

What you can do is to put your private ssh key in the same folder as your playbook is and add a ansible.cfg file where you define the user and ssh_key location.

[defaults]
hostfile = hosts
remote_user = userXX
private_key_file = .ssh_key
host_key_checking = False

Good luck!

James Dunn
  • 8,064
  • 13
  • 53
  • 87
nelasx
  • 191
  • 1
  • 2
  • 9