Deploy via Jenkins


I’m trying to run the deploy via jenkins but I get a strange error.

[workspace] $ ansible-playbook /var/lib/jenkins/jobs/deploystaging/workspace/trellis/deploy.yml -i /tmp/inventory8536384402828268657.ini -f 5
ERROR! the role 'f500.project_deploy_module' was not found in /var/lib/jenkins/jobs/deploystaging/workspace/trellis/roles:/var/lib/jenkins/jobs/deploystaging/workspace/trellis:/etc/ansible/roles:/var/lib/jenkins/jobs/deploystaging/workspace/trellis/roles

The error appears to have been in '/var/lib/jenkins/jobs/deploystaging/workspace/trellis/roles/deploy/meta/main.yml': line 2, column 16, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

dependencies: ['f500.project_deploy_module']
               ^ here

I get this error too when I try something like
ansible-playbook trellis/deploy.yml -e env=staging -e
in the cli.

The command always has to run in the directory of the playbook. Is that a thing from ansible or is it just a configuration issue?

Any suggestions?

You need to run ansible-galaxy install -r requirements.yml as our Installation say.

FYI: that dependency has been removed in the latest Trellis which requires Ansible 2.0. The deploy helper module is built-in now.

Thanks for the fast response!

I did this already! From a different directory on the same vm the deploy works. But only if i run the command inside the trellis directory.

PS: I use the latest trellis version (0.9.5)

//EDIT: sry… I messed up with the trellis update. But the problem is still there:

root@jenkins:/var/lib/jenkins/jobs/deploystaging/workspace/trellis# ansible-playbook deploy.yml -e env=staging -e --> That works

root@jenkins:/var/lib/jenkins/jobs/deploystaging/workspace# ansible-playbook trellis/deploy.yml -e env=staging -e [WARNING]: provided hosts list is empty, only localhost is available --> That not…

//EDIT2: I figured out that’s a problem with the missing ansible.cfg if I run the command outside the trellis directory. When I move the ansible.cfg in the root directory of the trellis project (and adjust the parameters inside) it works. But that’s unfortunally no solution for the jenkins deploy.

I’m confused, why are you running the ansible playbook from another directory? I’ve always run it from the trellis directory. Could you give that a try?

Unfortunally jenkins will allways run any cli commands via absolute paths.

But I’ve found a solution:

//EDIT: But the ssh-forwarding is tricky. Without the ansible.cfg the ssh parameters are missing… I think I have to play around with the inventory files^^

Any suggestions for a clean solution?

You should be able to specify an alternate path to ansible.cfg in the command through Jenkins. Check out man ansible-playbook.

I finally find a stable solution to deploy trellis via jenkins!

The ansible plugin for jenkins that I mentioned did not work for me because I couldn’t clone my bedrock repo on the target stage. The ssh forwarding doesn’t work correctly because the plugin obviously doesn’t use the ssh-agent that I startet at the first step of the jenkins job. But when I excecute the ansible-playbook command in a shell-block of jenkins it works.

eval $(ssh-agent -s) ssh-add cp $WORKSPACE/trellis/ansible_jenkins.cfg ~/.ansible.cfg ansible-playbook $WORKSPACE/trellis/deploy.yml -i $WORKSPACE/trellis/hosts -e env=staging -e

# colorized output in the jenkins console
force_color = True

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

Topic solved - thanks for your help!!


I figured out a better solution especially for newer versions of trellis (now 0.9.7):

  1. Add an additional deploy script:
    #!/usr/bin/env bash cd $3 ./ $1 $2
    This is important to run the deploy script right in the trellis directory.

  2. Then run in the jenkins job following:
    eval 'ssh-agent -s' ssh-add chmod +x $WORKSPACE/trellis/ chmod +x $WORKSPACE/trellis/ $WORKSPACE/trellis/ staging $WORKSPACE/trellis

I don’t know if it’s the best way to integrate a trellis deploy job to jenkins. But maybe it helps someone.