2015-11-20 34 views
0

Ansible:1.9.2(因此使用wget而不是get_url)。 的Linux CentOS的6.5ansible - 下載java jdk - 錯誤:在任務中指定的多個動作:'命令'

運行下面的命令並得到以下錯誤消息:

$ 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」,我已經創造了缺省的/ 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 /任務/ main.yml爲:

$貓的角色/ JAVA /任務/ 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

每個任務只能有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 }}" 
+0

感謝皮特。這解決了它。你能幫我解決這個問題嗎?我想知道我的角色/ java/defaults/main.yml是否正確?在我提出了相關更改後,我收到以下錯誤消息。任務:[java |下載Java/JDK版本] ************************************* 失敗:[server01.poc .jenkins] =>(item = {'key':'java7_60','value':{'dist_file':u'jdk - {#item.value.version#} - {#item.value.classifier#} - {#item.value.ext#}','ext':'tar.gz','version':'1.7.60','dist_url':u'{#artifactory_url#}/{#item.value.group_path #}/{#item.value.version#}/{#dist_file#}', –

+0

'group_path':'com/oracle/jdk','classifier':'linux-x64'}})=> {「changed 「:true,」cmd「:[」wget「,」-q「,」{#artifactory_url#}/{#item.value.group_path#}/{#item.value.version#}/{#dist_file#} 「],」delta「:」0:00:00.005900「,」結束「:」2015-11-23 12:36:24.131327「,」item「:{」key「:」java7_60「,」value「:{ 「classifier」:「linux-x64」,「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#}「, –

+0

」ext「:」ta r.gz「,」group_path「:」com/oracle/jdk「,」version「:」1.7.60「}},」rc「:4,」start「:」2015-11-23 12:36:24.125427 「,」warnings「:[」考慮使用get_url模塊而不是運行wget「]} –