我想在 ubuntu 机器上安装 nginx 并使用 Ansible playbook 启动服务,
我在运行剧本“()时遇到此错误:在第 7 行第 10 列的上下文中不允许映射值”
这是我尝试过的代码:
---
-
hosts: all
tasks:
- name: ensure nginx is at the latest version
apt: name=nginx state=latest
- name: "start nginx"
service:
name: nginx
state: started
所以,我发现那里有一个拼写错误,
name:ensure
,你真的需要这个空间。
此外,您应该为您的剧本命名,并且在不必要/更简单时避免内联(apt:name=nginx state=latest)。
此外,您可以查看使用模块的完整命名(
service
-> ansible.builtin.service
)。
---
- name: set up webserver
hosts: all
tasks:
- name: ensure nginx is at the latest version
apt:
name: nginx
state: latest
- name: start nginx
service:
name: nginx
state: started
enabled: yes # if you want to also enable nginx