I'm trying to dynamically pass an Ansible inventory limit within Groovy. I can do this in a Freestyle project but am struggling to figure out how to pass that environment var.
I have a String Parameter defined, CLUSTER. In the Freestyle project, I have "Host subset" == $CLUSTER and it works. Console output shows something like:
# ansible-playbook -i ec2.py -l cluster1 tasks/ping2.yml
How do I reference that in Groovy? I've tried several ways to encant this but am failing. Trying to pull it from env.CLUSTER returns null.
def playbookCluster = env.CLUSTER
echo "cluster is $playbookCluster"
And I don't know the right syntax to pass to ansiblePlaybook:
ansiblePlaybook colorized: true, credentialsId: '7090458f-4fd0-44eb-9159-d16d6024d58b', installation: 'ansible 2.1.1.0', inventory: 'ec2.py', limit: '${CLUSTER}', playbook: 'tasks/jenkins-ping.yml', sudoUser: null
Incidentally, I pass a couple other environment variables and pull them into the Playbook and that works.
vars:
- hostgroup: "{{ lookup('env','HOSTGROUP') }}"
- mirror: "{{ lookup('env','MIRROR') }}"