2016-01-28 39 views
1

這裏是我的目錄結構:Ansible:在相互矛盾的任務操作語句/ main.yml文件

/roles 
    /apache 
     /files 
     /handlers 
     /meta 
     /tasks 
     /templates 
     /vars 
ansible.cfg 
hosts 
playbook.yml 

這是我的任務/ main.yml文件內容:

--- 
- name: Add Apache2 repository 
    apt_repository: repo='ppa:ondrej/apache2' state=present 
    register: apacherepositoryinstalled 

- name: Install Apache2 
    apt: pkg=apache2 state=latest update_cache=true 
    when: apacherepositoryinstalled|success 
    register: apacheinstalled 
    service: name=apache2 state=started 

- name: Enable rewrite module 
    apache2_module: state=present name=rewrite 
    when: apacheinstalled|success 
    register: rewritemoduleenabled 

- name: Add production virtual host configuration 
    template: src=production.conf.j2 dest=/etc/apache2/sites-available/production.conf owner=root group=root 

- name: Enable production virtual host configuration 
    file: src=/etc/apache2/sites-available/production.conf dest=/etc/apache2/sites-enabled/production.conf 

- name: Add staging virtual host configuration 
    file: src=staging.conf.j2 dest=/etc/apache2/sites-available/staging.conf owner=root group=root 

- name: Enable staging virtual host configuration 
    file: src=/etc/apache2/sites-available/staging.conf dest=/etc/apache2/sites-enabled/staging.conf 

- name: Reload Apache2 Service 
    service: name=apache2 state=reloaded 

這裏是以下由Ansible腳本引發的錯誤消息:

The error appears to have been in '/home/vagrant/ansible/roles/apache/tasks/main.yml': line 6, column 4, but may be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

- name: Install Apache2 
^here 

我是否缺少明顯的東西?

在此先感謝。

回答

3

您有多個指定的操作。 service必須單獨行動。將其更改爲:

- name: Install Apache2 
    apt: pkg=apache2 state=latest update_cache=true 
    when: apacherepositoryinstalled|success 
    register: apacheinstalled 
- service: name=apache2 state=started 
+0

Thanks!我可以將「通知」指定爲單個任務嗎?當我嘗試做 - 名稱:重新加載Apache2服務 - 通知:重新啓動Apache它告訴我沒有指定操作。 –

相關問題