HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Passing parameters from Jenkins to Ansible playbook

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
jenkinspassingplaybookfromparametersansible

Problem

How can I pass parameters from Jenkins to my Ansible playbook? Eg. I want to take IP address from users and pass it to the playbook so that it will execute only on those machines.

Solution

You can use -e switch for that purpose:

ansible-playbook -e 'foo=${FOO}'


where the FOO can be defined in the Jenkins envirionment variables. If it is defined within the parameters block of your Jenkinsfile, then you need to use ${params.foo}. Then, the value can be accessed by the Ansible playbook with {{ foo }}.

Code Snippets

ansible-playbook -e 'foo=${FOO}'

Context

StackExchange DevOps Q#10111, answer score: 2

Revisions (0)

No revisions yet.