Ansible Playbook设置Nginx

时间:2019-04-08 07:42:35

标签: ansible

我写了剧本,将ngix安装在客户端计算机上。由于某些语法错误,我被卡住了。这是我的第一次尝试,我不知道问题出在哪里。

错误:

ERROR! Syntax Error while loading YAML.
  mapping values are not allowed in this context

The error appears to have been in '/private/etc/ansible/nginx.yml': line 6, column 10, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:
   - name: Installs Nginx r
      apt: pkg=nginx state=installed update_cache=true
         ^ here

剧本:

---
   - hosts: myServers
     become: yes
     tasks:
   - name: Installs Nginx r
      apt: pkg=nginx state=installed update_cache=true
      notify:
    - start nginx 

  handlers:
      name: start  nginx
      service: nginx 
      state: started

1 个答案:

答案 0 :(得分:0)

缩进是错误的。正确的语法如下。

---
- hosts: myServers
  become: yes
  tasks:
    - name: Installs Nginx r
      apt:
        pkg: nginx
        state: installed
        update_cache: true
      notify: start nginx
  handlers:
    - name: start nginx
      service:
        name: nginx
        state: started

FWIW。有一个正在积极开发中的官方Ansible NGINX Role