Recently I had to deploy AppDynamics agents out to some systems that ran both tomcat and JBOSS workloads, and here’s how I used one playbook to rule them all.
1 - Figure out which platform I was dealing with
#check to see if we're tomcat or jboss
- name: Check to see if tomcat user exists
- name: check to see if jbossadm user exists
As you can see, I’m doing a simple stat module check on the home directory of the user running the java workload here. In our use case those 2 users would never coexist on a server.
2 - Swap ownership on files/folders based on our findings above
#creates directory path
- name: Create the directories for site specific configurations owned by tomcat8
- name: Create the directories for site specific configurations owned by jbossadm
So, in each case we’re creating the same folder path and changing linux file system ownership based on which platform we’re running this ansible playbook on.
The stat module and when conditions are pretty powerful tools you can use to make Ansible super flexible without having to pass a bunch of extra parameters in to control which tasks get executed in your playbooks.