2017-04-07 237 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