【问题标题】:Ansible Playbook to install nginx serverAnsible Playbook 安装 nginx 服务器
【发布时间】:2022-12-19 12:13:32
【问题描述】:

我想在 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

【问题讨论】:

    标签: python nginx ansible devops


    【解决方案1】:

    所以,我发现那里有一个错字 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-02
      • 2022-06-29
      • 1970-01-01
      • 1970-01-01
      • 2020-03-28
      • 1970-01-01
      • 2021-12-18
      • 2018-01-04
      相关资源
      最近更新 更多