Ansible Galaxy

The following example shows how to deploy a web application on Tomcat using the AnsibleGalaxy component. We will use the galaxy zaxos.tomcat-ansible-role to deploy Tomcat.

Fig. Ansible Galaxy

tip

You can find this example under New Application / Topology Template / Ansible-Galaxy.

Step 1. Create compute

  • Create a compute node with access to public network.
  • Set distribution to centOS.

Fig. Create a compute with public access

info

The ansible galaxy in this example only works on CentOS/RHEL 7 so we have to set the distribution for the compute node.

Step 2. Create AnsibleGalaxy Tomcat

  • Drop the AnsibleGalaxy on the compute node. Name it Tomcat.
  • Set galaxy_name to zaxos.tomcat-ansible-role. This is the name of the galaxy to install.
  • Set component_version to 1.3.2. This is the tag of the GIT repository zaxos.tomcat-ansible-role. By default, it is set to master.
  • Set port to 8080. The orchestrator will create a security group to allow incoming traffic on port 8080 automatically.

Fig. Ansible Galaxy

Step 3. Configure AnsibleGalaxy

  • Write an ansible variable (e.g., tomcat_vars.yml).
tomcat_version: 8.5.23
tomcat_install_path: /opt
tomcat_port_connector: 8080
tomcat_permissions_production: True
tomcat_users:
- username: "tomcat"
password: "t3mpp@ssw0rd"
roles: "tomcat,admin,manager,manager-gui"

In this example, we configure the ansible galaxy to deploy Tomcat at /opt, listening on port 8080.

info

The ansible variables above are from the galaxy zaxos.tomcat-ansible-role. Take a look at the given galaxy to see which variables are available and customize them according to your needs.

  • Upload tomcat_vars.yml to the artifact ansible_variables.

Fig. Ansible Galaxy

  • By default, Tomcat uses Ipv6, so we write an ansible task (e.g., setenv.yml) to configure Tomcat to listen on IPv4:
- name: "Tell tomcat to listen for ipv4 instead of ipv6"
copy:
dest: "/opt/tomcat/bin/setenv.sh"
content: |
JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true"
owner: tomcat
group: tomcat
- name: "Restart tomcat to enable ipv4"
shell: |
./shutdown.sh
./startup.sh
args:
chdir: /opt/tomcat/bin/
executable: /bin/bash
- name: "Flush firewall (optional)"
shell: iptables -F INPUT
args:
executable: /bin/bash
  • Upload setenv.yml to the artifact configure.

Step 4. Deploy the .war file

  • Drop GetUrl on the AnsibleGalaxy component. This component downloads a file on the Compute node after the Ansible Galaxy has completed.
  • Check the box ansible_become. This makes sure the file is created on the Compute node with no permission issues.
  • Set url to https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war. This will download the sample.war file from the given url. Here we use the sample.war file from the Tomcat sample web application.
  • Set dest to /opt/tomcat/webapps. This is the webapps location inside the CATALINA_HOME of Tomcat. The sample.war file will be created in this directory.
  • Set group to tomcat. This will set the permission of the sample.war file to the group tomcat. The ansible galaxy zaxos.tomcat-ansible-role will create this group for you beforehand.

Fig. Ansible Galaxy

Step 5. Define the deployment output (optional)

  • Click on the AnsibleGalaxy Tomcat.
  • Select app_url. The deployment will output the public IP address of the compute node in the GUI for you.

Fig. Ansible galaxy output

Expected result

  • Access http://<public_ip>:8080/sample/

Fig. Sample web application