Hi there,
in my hosts file I have a group “product”.
This group has 4 hosts: “product-et”, “product-at”, “product-qs” and “product-pr”.
“product” has special properties which are valid for all 4 hosts.
Each of the 4 hosts has special properties which are valid only for this special host.
Now I want to write a playbook which generates jenkins-jobs.
I want to call this playbook with “hosts=product”.
The playbook itself has to generate some jobs for the whole product. So each of this jobs should exist only once in Jenkins.
Futher this playbook has to generate some jobs for each of the 4 hosts. So each of this jobs should exist 4 times with only differences which depend on the host properties.
For each of these jobs the properties of the group and the properties of each of the hosts are necessary.
My problem now is that if I call this playbook with “hosts=product” it will generate each of the group jobs 4 times. So it’s 3 times to much.
So now my question is how to realize this that I am able to have a mix of one time execution tasks (for the group) and tasks that have to be executed for each host?
Regards,
Tom
Two ideas:
You can have more than one play in a playbook.
I might have misunderstood your, but I believe you are looking for run_once.
https://docs.ansible.com/ansible/playbooks_delegation.html#run-once
With run_once on a task, the task is only executed on one of the hosts in the play.
Hi,
thx for the hints, Mr. Kastl and Mr. Olstad.
The hints from Mr. Kastl are not suitable for my purpose because I’m calling the playbook only with the product name and only one time.
Also I want to create the jobs don’t matter if they are exist or not. The reason is that it’s possible that I changed something in the config.xml of an maybe existing job. So if I call the playbook I want it to change also the existing jobs to deliver my changes to jenkins.
So it seems that the hint from Mr. Olstad hits the bull’s eye. I tested the behavior with run_once and it looks fine.
Thank you once more Mr. Kastl and Mr. Olstad.
Regards,
Tom
Hi,
Glad the run_once works for you.
The hints from Mr. Kastl are not suitable for my purpose because
I'm calling the playbook only with the product name and only one
time.
But I am not sure you got my approach. You do not need to call the
playbook multiple times, even if it contains two plays.
Also I want to create the jobs don't matter if they are exist
or not. The reason is that it's possible that I changed something
in the config.xml of an maybe existing job. So if I call the
playbook I want it to change also the existing jobs to deliver my
changes to jenkins.
But doesn't this mean that the jobs exist multiple times in jenkins,
with different parameters?
Johannes