Reputation: 27879
I have an Ansible playbook which worked on a different machine.
But here it fails:
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
What could be wrong?
Upvotes: 1
Views: 3662
Reputation: 78
guettli's answer is correct but you can also make it shorter, calling the apt module only once:
---
- 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
Upvotes: 4
Reputation: 27879
If the machine was setup up just some seconds ago, then you need to run apt update
at least once.
You can do it like this via 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
Upvotes: 2