Ansible:tasks / main.yml文件中的冲突操作语句

时间:2016-01-28 17:02:16

标签: python ansible ansible-playbook

这是我的目录结构:

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

这是我的tasks / 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

我错过了一些明显的东西吗?

提前致谢。

1 个答案:

答案 0 :(得分:3)

您指定了多个操作。 service必须采取单独行动。将其更改为:

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