Reputation: 11193
i'm having a jar file that installs tomcat with a website. so i have following tasks download jar file
, install jar
file and delete jar file
. however i want ansible to tell that it is already installed instead of downloading and trying to install again. how can i achieve such?
- name: Downloading installer
get_url:
url: http://[URl]/installfile.jar
dest: "/opt"
- name: Installing jar file
shell: java -jar "/opt/installfile.jar"
- name: Removing installer
file:
state: absent
path: "/opt/installfile.jar"
Upvotes: 1
Views: 1577
Reputation: 66
You can use creates
arg on the install task at least, so that the java program will only run when certain file does not yet exist. Ansible will create such file the first time the task runs.
Something like:
- name: Installing jar file
shell: java -jar "/opt/installfile.jar"
args:
creates: /opt/installfile-check
Or if you want to condition the three tasks to run only when Tomcat is not installed, you need to first run a program that checks whether it is installed and register its result in a variable that other tasks can use to determine if they need to run using when
.
- name: Check to see if Tomcat is installed
shell: "command --that --checks" # Just an example, obviously
register: tomcat_is_installed
You can then include the Tomcat playbook only when it is not installed:
- name: This playbook will only be included when Tomcat is not installed
include: tomcat-playbook.yml
when: tomcat_is_installed.rc != 0
Upvotes: 1