Hi there,
The above lab has an issue when installing apache 2 on ubuntu.
Here is my code:
---
- name: Install apache
hosts: all
become: yes
gather_facts: true
tasks:
- name: Install apache2 when ubuntu
apt:
name: apache2
state: present
when: ansible_distribution == "Ubuntu"
- name: Install httpd when Centos
yum:
name: httpd
state: present
when: ansible_distribution == "CentOS"
I also noticed that under “state:” if I put installed, this throws an error.
Is it possible that the ansible version is older, thus not aware of the option?
Here is the version
[thor@ansible-controller playbooks]$ ansible --version | head -1
ansible [core 2.14.17]
[thor@ansible-controller playbooks]$
Here is the actual answer given
---
- name: Install apache
hosts: all
gather_facts: True
tasks:
- name: install apache2 when Ubuntu
package:
name: apache2
state: present
when: ansible_distribution == "Ubuntu"
- name: install httpd when CentOS
package:
name: httpd
state: present
when: ansible_distribution == "CentOS"
Here is the error that appears:
[thor@ansible-controller playbooks]$ ansible-playbook -i inventory install_apache.yml
PLAY [Install apache] ********************************************************************
TASK [Gathering Facts] *******************************************************************
ok: [web2]
ok: [web1]
TASK [Install apache2 when ubuntu] *******************************************************
skipping: [web1]
[WARNING]: Updating cache and auto-installing missing dependency: python3-apt
fatal: [web2]: FAILED! => {"changed": false, "cmd": "apt-get update", "msg": "E: The repository 'http://security.ubuntu.com/ubuntu lunar-security Release' no longer has a Release file.\nE: The repository 'http://archive.ubuntu.com/ubuntu lunar Release' no longer has a Release file.\nE: The repository 'http://archive.ubuntu.com/ubuntu lunar-updates Release' no longer has a Release file.\nE: The repository 'http://archive.ubuntu.com/ubuntu lunar-backports Release' no longer has a Release file.", "rc": 100, "stderr": "E: The repository 'http://security.ubuntu.com/ubuntu lunar-security Release' no longer has a Release file.\nE: The repository 'http://archive.ubuntu.com/ubuntu lunar Release' no longer has a Release file.\nE: The repository 'http://archive.ubuntu.com/ubuntu lunar-updates Release' no longer has a Release file.\nE: The repository 'http://archive.ubuntu.com/ubuntu lunar-backports Release' no longer has a Release file.\n", "stderr_lines": ["E: The repository 'http://security.ubuntu.com/ubuntu lunar-security Release' no longer has a Release file.", "E: The repository 'http://archive.ubuntu.com/ubuntu lunar Release' no longer has a Release file.", "E: The repository 'http://archive.ubuntu.com/ubuntu lunar-updates Release' no longer has a Release file.", "E: The repository 'http://archive.ubuntu.com/ubuntu lunar-backports Release' no longer has a Release file."], "stdout": "Ign:1 http://archive.ubuntu.com/ubuntu lunar InRelease\nIgn:2 http://security.ubuntu.com/ubuntu lunar-security InRelease\nIgn:3 http://archive.ubuntu.com/ubuntu lunar-updates InRelease\nErr:4 http://security.ubuntu.com/ubuntu lunar-security Release\n 404 Not Found [IP: 185.125.190.81 80]\nIgn:5 http://archive.ubuntu.com/ubuntu lunar-backports InRelease\nErr:6 http://archive.ubuntu.com/ubuntu lunar Release\n 404 Not Found [IP: 185.125.190.81 80]\nErr:7 http://archive.ubuntu.com/ubuntu lunar-updates Release\n 404 Not Found [IP: 185.125.190.81 80]\nErr:8 http://archive.ubuntu.com/ubuntu lunar-backports Release\n 404 Not Found [IP: 185.125.190.81 80]\nReading package lists...\n", "stdout_lines": ["Ign:1 http://archive.ubuntu.com/ubuntu lunar InRelease", "Ign:2 http://security.ubuntu.com/ubuntu lunar-security InRelease", "Ign:3 http://archive.ubuntu.com/ubuntu lunar-updates InRelease", "Err:4 http://security.ubuntu.com/ubuntu lunar-security Release", " 404 Not Found [IP: 185.125.190.81 80]", "Ign:5 http://archive.ubuntu.com/ubuntu lunar-backports InRelease", "Err:6 http://archive.ubuntu.com/ubuntu lunar Release", " 404 Not Found [IP: 185.125.190.81 80]", "Err:7 http://archive.ubuntu.com/ubuntu lunar-updates Release", " 404 Not Found [IP: 185.125.190.81 80]", "Err:8 http://archive.ubuntu.com/ubuntu lunar-backports Release", " 404 Not Found [IP: 185.125.190.81 80]", "Reading package lists..."]}
TASK [Install httpd when Centos] *********************************************************
ok: [web1]
PLAY RECAP *******************************************************************************
web1 : ok=2 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
web2 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
[thor@ansible-controller playbooks]$
Is this Lab not upto date, hence throwing errors?
Regards
Elvy