如何使用ansible playbook安装maven?

All*_*Liu 5 maven ansible

- name: Download Apache Maven
  get_url: url=http://apache.claz.org/maven/maven-3/3.1.1/binaries/apache-maven--bin.tar.gz dest=/tmp/apache-maven--bin.tar.gz

- name: Untar Maven
  shell: chdir=/tmp creates=/opt/apache-maven- tar -zxf apache-maven--bin.tar.gz -C /opt
Run Code Online (Sandbox Code Playgroud)

那么,我应该怎么安装maven呢?

sma*_*nan 3

我认为您可以更新$PATH链接到下载的Maven文件:

# your two commands

- name: Download Apache Maven 
  get_url: url=http://apache.claz.org/maven/maven-3/3.1.1/binaries/apache-maven--bin.tar.gz dest=/tmp/apache-maven-3.1.1-bin.tar.gz

- name: Untar Maven 
  shell: chdir=/tmp creates=/opt/apache-maven-3.1.1 tar -zxf apache-maven-3.1.1-bin.tar.gz -C /opt

# What is missing

- name: Update path for maven use
  shell: export PATH=/opt/apache-maven-3.1.1/bin:$PATH
Run Code Online (Sandbox Code Playgroud)

或者只需从仓库安装maven(如果您不需要非常具体的版本):

- name: install maven (and other packages if needed)
  become: yes
  apt: pkg={{ item }} state=latest update_cache=yes cache_valid_time=3600
  with_items:
    - maven
Run Code Online (Sandbox Code Playgroud)

注:这里可以通过添加项目来安装其他包with_items