2017-04-07 241 views
0

我有一個安裝tomcat的網站的jar文件。所以我有以下任務download jar file,install jar文件和delete jar file。但是我想知道它已經安裝,而不是下載並嘗試再次安裝。我怎麼能實現這樣的?安裝jar檢查是否已安裝

- 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" 
+0

您需要決定要如何檢查安裝的軟件包。無論您是要檢查某個文件的存在,還是運行可執行文件並檢查輸出,或者手動在目標服務器上的文件中設置標誌,我不確定任何人,但你可以做到。當你決定你想要什麼,並有一個特定的問題,然後尋求幫助。 – techraf

回答

0

您可以使用安裝任務creates ARG至少,這樣當某個文件不存在的java程序才能運行。 Ansible將在第一次運行任務時創建這樣的文件。

喜歡的東西:

- name: Installing jar file 
    shell: java -jar "/opt/installfile.jar" 
    args: 
    creates: /opt/installfile-check 

或者,如果你想調理三項任務未安裝Tomcat的,只有當運行,你需要先運行一個程序,檢查它是否已安裝並在登記其結果其他任務可用於確定是否需要使用when運行的變量。

- name: Check to see if Tomcat is installed 
    shell: "command --that --checks" # Just an example, obviously 
    register: tomcat_is_installed 

然後,您可以包括沒有安裝,只有當它Tomcat的劇本:

- name: This playbook will only be included when Tomcat is not installed 
    include: tomcat-playbook.yml 
    when: tomcat_is_installed.rc != 0