Ansible:没有匹配'nginx'的软件包可用

z31licg0  于 2023-01-16  发布在  Nginx
关注(0)|答案(2)|浏览(163)

我有一个Ansible剧本,它在另一台机器上工作。
但它在这里失败了:

fatal: [coffee-and-sugar.club]: FAILED! => 
{"changed": false, "msg": "No > package matching 'nginx' is available"}
---
- hosts: all
  tasks:
    - name: ensure nginx is at the latest version
      apt: name=nginx state=latest
    - name: start nginx
      service:
          name: nginx
          state: started

有什么问题吗?

eqqqjvef

eqqqjvef1#

guettli的答案是正确的,但你也可以把它缩短,只调用apt模块一次:

---
- hosts: all
  tasks:
    - name: Update and upgrade apt packages
      apt:
        name: nginx
        state: latest
        update_cache: yes
        upgrade: yes
    - name: start nginx
      service:
          name: nginx
          state: started
8fq7wneg

8fq7wneg2#

如果机器是几秒钟前安装的,那么您至少需要运行一次apt update
您可以通过Ansible这样做:

---
- hosts: all
  tasks:
    - name: Update and upgrade apt packages
      apt:
        update_cache: yes
        upgrade: yes
    - name: ensure nginx is at the latest version
      apt: name=nginx state=latest
    - name: start nginx
      service:
          name: nginx
          state: started

相关问题