我正在尝试使用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
答案 0 :(得分:2)
您的缩进不正确。这应该起作用:
---
- 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
答案 1 :(得分:0)
请尝试如下操作。我认为缩进是这里的问题。
---
- hosts: all
become: yes
tasks:
- name: Install httpd
yum:
name: httpd
state: present
notify: "restart apache"
答案 2 :(得分:0)
正确的解决方法如下:
---
- hosts: all
become: yes
tasks:
- name: Install httpd
yum:
name: httpd
state: present
- 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 httpd
handlers:
- name: restart httpd
service:
name: httpd
state: restarted