This repo contains ansible code to configure jobs in Jenkins using Jinja2 templating
When cloning from github, simply run:
rake
When using galaxy, simply run:
ansible-galaxy install Azulinho.azulinho-jenkins-reconfigure-jobs-using-jinja2
To consume this role, place the following variables into group_vars/all or into a wrapper_role <wrapper_role/vars/main.yaml>
VARIABLES:
azulinho_jenkins_reconfigure_jobs_using_jinja2:
jobs:
jinja2_base_template:
options: &base_template_options { disabled: false,
concurrentbuild: false }
buildWrappers: &base_template_wrappers
- &BuildTimeOutWrapper_defaults { type: 'BuildTimeoutWrapper',
timeoutMinutes: 60,
strategy: 'AbsoluteTimeOutStrategy',
failBuild: true,
writingDescription: false }
- &TimeStamper_defaults { type: 'Timestamper',
options: none }
- &AnsiColor_defaults { type: 'AnsiColor',
colorMapName: xterm }
jinja2_run_ansible: &jinja2_run_ansible
description: "Executes Ansible"
options: { disabled: false,
blocks: [ 'downstream', 'upstream' ],
concurrentbuild: true }
parameters: &jinja2_run_ansible_parameters
- &inventory_file { name: 'INVENTORY_FILE',
type: 'choice',
description: 'Which Inventory File to use',
choices: { type_string: ['vagrant', 'dev', 'qa', 'prd']}}
- &playbook { name: 'PLAYBOOK',
type: 'choice',
description: 'Which playbook to execute',
choices: { type_string: ['jenkins.yml', 'zabbix.yml', 'site.yml']}}
- &limit { name: "LIMIT",
type: 'string',
description: "Ansible --limit",
default: "all" }
- &tags { name: "TAGS",
type: 'string',
description: "Ansible --tags",
default: "" }
- &start_at_task { name: "START_AT_TASK",
type: 'string',
description: "Ansible --start-at-task",
default: "" }
- &release { name: "RELEASE",
type: 'string',
description: "RELEASE number to use",
default: "latest" }
- &vault { name: "VAULT",
type: 'password',
description: "Ansible Vault Password",
default: "" }
scm:
- { type: 'git',
url: 'https://github.com/Azulinho/ansible-jenkins-showcase.git',
branches: ['*/master'] }
builders:
- { type: 'shell',
command_lines: [
"#!/bin/bash",
"export PATH=/usr/local/bin:$PATH",
"export PYTHONUNBUFFERED=1",
"echo $VAULT > .vault",
"ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u vagrant -s -i $INVENTORY_FILE -l $LIMIT $PLAYBOOK --vault-password-file .vault" ]}
buildWrappers: *base_template_wrappers
jinja2_deploy_zabbix:
<<: *jinja2_run_ansible
parameters: [
<<: *limit,
<<: *tags,
<<: *start_at_task,
<<: *release,
<<: *vault,
{ name: 'PLAYBOOK',
type: 'string',
description: 'Which playbook to execute',
default: 'zabbix.yml'},
{ name: 'INVENTORY_FILE',
type: 'string',
description: 'Which Inventory File to use',
default: 'vagrant'} ]
publishers:
- { type: 'parametrizedTrigger',
projects: ['jinja2_deploy_zabbix_checks'],
parameters: ['<hudson.plugins.parameterizedtrigger.CurrentBuildParameters/>'],
condition: 'success'}
jinja2_deploy_zabbix_checks:
<<: *jinja2_run_ansible
parameters: [
<<: *limit,
<<: *tags,
<<: *start_at_task,
<<: *release,
<<: *vault,
{ name: 'PLAYBOOK',
type: 'string',
description: 'Which playbook to execute',
default: 'zabbix-checks.yml'},
{ name: 'INVENTORY_FILE',
type: 'string',
description: 'Which Inventory File to use',
default: 'vagrant'} ]
publishers:
- { type: 'parametrizedTrigger',
projects: ['jinja2_run_zabbix_tests'],
parameters: ['<hudson.plugins.parameterizedtrigger.CurrentBuildParameters/>'],
condition: 'success'}
jinja2_run_zabbix_tests:
<<: *jinja2_run_ansible
builders:
- { type: 'shell',
command_lines: [
"#!/bin/bash",
"echo SUCESS" ]}
options: *base_template_options
buildWrappers: *base_template_wrappers
jinja2_deploy_template:
options: &deploy_template_options { disabled: false,
blocks: [ 'downstream',
'upstream' ],
concurrentbuild: true }
builders:
- { type: 'shell',
command_lines: [
"#!/bin/bash",
"echo $VAULT > .vault",
"ansible-playbook -s -i $INVENTORY_FILE -l $LIMIT $PLAYBOOK --vault-password-file .vault" ]}
jinja2_example1:
options: *deploy_template_options
parameters:
- { name: "PARAMETER1",
type: 'string',
description: "PARAMETER 1",
default: "all" }
builders:
- { type: 'shell',
command_lines: [
"#!/bin/bash",
"echo deploy_job1" ]}
buildWrappers: *base_template_wrappers
publishers:
- { type: 'parametrizedTrigger', projects: ['deploy_job2'], condition: 'success', parameters: ['VAR1=var1', 'VAR2=var2'], triggerWithNoParameters: false }
jinja2_example2:
options: *deploy_template_options
builders:
- { type: 'shell',
command_lines: [
"#!/bin/bash",
"echo deploy_job2" ]}
buildWrappers: [ *BuildTimeOutWrapper_defaults, *TimeStamper_defaults, *AnsiColor_defaults ]
publishers:
- { type: 'parametrizedTrigger', projects: ['deploy_job3'], condition: 'success', parameters: ['VAR1=var1', 'VAR2=var2'], triggerWithNoParameters: false }
jinja2_example3: { options: *deploy_template_options, builders: [ { type: 'shell', command_lines: [ "#!/bin/bash", "echo deploy_job3" ]} ], buildWrappers: *base_template_wrappers , publishers: [ {type: 'parametrizedTrigger', projects: ['deploy_job4']} ] }
jinja2_example4: { options: *deploy_template_options, builders: [ { type: 'shell', command_lines: [ "#!/bin/bash", "echo deploy_job4" ]} ], buildWrappers: *base_template_wrappers , publishers: [ {type: 'parametrizedTrigger', projects: ['deploy_job5']} ]}
jinja2_example5: { options: *deploy_template_options, builders: [ { type: 'shell', command_lines: [ "#!/bin/bash", "echo deploy_job5" ]} ], buildWrappers: *base_template_wrappers , publishers: [ {type: 'parametrizedTrigger', projects: ['deploy_job6']} ]}
jinja2_example6: { options: *deploy_template_options, builders: [ { type: 'shell', command_lines: [ "#!/bin/bash", "echo deploy_job6" ]} ], buildWrappers: *base_template_wrappers }