ansible - 下载java jdk - 错误:任务中指定的多个动作:'命令'

时间:2015-11-20 23:18:40

标签: variables jinja2 ansible roles ansible-playbook

Ansible:1.9.2(因此使用wget而不是get_url)。 Linux CentOS 6.5

运行以下命令并收到以下错误消息:

$ ansible-playbook site.yml ${sudo_user_opts} -i hosts -u builduser --private-key ${DEPLOYER_KEY_FILE} --extra-vars "svr_type=${server_type} deploy_environment=${DEPLOY_ENVIRONMENT} ansible_user=${ANSIBLE_USER}

ERROR: multiple actions specified in task: 'command' and 'Download Java/JDK Versions'

知道我错过了什么。

角色" java"我创建的是default / main.yml:

$ cat roles/java/defaults/main.yml
---
java_versions:
  java7_60:
    version: 1.7.60
    group_path: com/oracle/jdk
    classifier: linux-x64
    ext: tar.gz
    dist_file: "jdk-{{item.value.version }}-{{ item.value.classifier }}-{{ item.value.ext }}"
    dist_url: "{{ artifactory_url }}/{{ item.value.group_path }}/{{ item.value.version }}/{{ dist_file }}"
  java7_67:
    version: 1.7.67
    group_path: com/oracle/jdk
    classifier: linux-x64
    ext: tar.gz
    dist_file: "jdk-{{item.value.version }}-{{ item.value.classifier }}-{{ item.value.ext }}"
    dist_url: "{{ artifactory_url }}/{{ item.value.group_path }}/{{ item.value.version }}/{{ dist_file }}"
  java8_45:
    version: 1.8.45
    group_path: com/oracle/jdk
    classifier: linux-x64
    ext: tar.gz
    dist_file: "jdk-{{item.value.version }}-{{ item.value.classifier }}-{{ item.value.ext }}"
    dist_url: "{{ artifactory_url }}/{{ item.value.group_path }}/{{ item.value.version }}/{{ dist_file }}"

角色some_common的默认值为\ main.yml:

---
# common vars
artifactory_url: http://artifactory.company.com:9050/virtual-repos

instance_home: "~"
tools_dir: "{{ instance_home }}/tools"
slaves_dir: "{{ instance_home }}/slaves"
build_user: 'builduser'
build_group: 'build'

common_download_dir: "/tmp"

任务内部角色:java / tasks / main.yml是:

$ cat roles / java / tasks / main.yml

---
- debug: msg="Downloading and installing Java versions - instance_home {{ instance_home }}"

- name: Download Java/JDK Versions
  debug: msg="Java {{ item.key }} is (jdk-{{ item.value.version }}-{{ item.value.classifier }}-{{ item.value.ext }})"
  command: wget -q "{{ item.value.dist_url }}"
    chdir="{{ common_download_dir }}"
    creates="{{ common_download_dir }}/{{ item.value.dist_file }}"
  with_dict: "{{ java_versions }}"

1 个答案:

答案 0 :(得分:1)

每项任务只能执行1次操作。 ansible内置模块debug计为一个动作,因此你必须将它作为一个独立的任务,如下所示:

- debug: msg="Java {{ item.key }} is (jdk-{{ item.value.version }}-{{ item.value.classifier }}-{{ item.value.ext }})"
  with_dict: "{{ java_versions }}"  

- name: Download Java/JDK Versions
  with_dict: "{{ java_versions }}"  
  command: wget -q "{{ item.value.dist_url }}"
    chdir="{{ common_download_dir }}"
    creates="{{ common_download_dir }}/{{ item.value.dist_file }}"