首页 > 解决方案 > 错误!“通知”不是 Play 的有效属性

问题描述

我正在尝试使用 Ansible-playbook 安装 LAMP。但我收到错误[如图所示]

我用于剧本的代码如下:-

---
- hosts: all
  become: yes
  tasks:
- name: Install httpd
   yum:
   name: httpd
   state: present
   notify: 
   - restart apache
- name: starting httpd service
   service:
   name: httpd
   enabled: yes
   state: started
- name: Installing php packages
   yum:
   name: "{{ item }}"
   state: present
  with_items:
  - php
  - php-mysql
  - php-pdo
  - php-gd
  - php-mbstring
  notify:
 -restart apache 
 handlers:
- name: restart apache
  service:
    name: httpd
    state: restarted

图像格式错误

标签: ansibledevopsplaybackansible-inventory

解决方案


您的缩进不正确。这应该有效:

---
- hosts: all
  become: yes
  tasks:
    - name: Install httpd
      yum:
        name: httpd
        state: present
      notify: 
        - restart apache

    - name: starting httpd service
      service:
         name: httpd
         enabled: yes
         state: started

    - name: Installing php packages
      yum:
        name: "{{ item }}"
        state: present
      with_items:
        - php
        - php-mysql
        - php-pdo
        - php-gd
        - php-mbstring
      notify:
        - restart apache 

  handlers:
    - name: restart apache
      service:
        name: httpd
        state: restarted

推荐阅读