Ansible Use yum module to install rpm Error: Request failed: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate v

Project scenario:

Today I used Ansible to install postgresql-13 and wrote the following test script from the official installation tutorial.

- hosts: postgresql
  gather_facts: false
  tasks:
    - name: install pg repo
      yum:
        name: https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
        state: present
    - name: install pg
      yum:
        name: postgresql13-server
        state: present
    - name:
      stat:
        path: "/var/lib/pgsql/data/pg_hba.conf"
      register: postgres_data
    - name:
      shell: "/usr/pgsql-13/bin/postgresql-13-setup initdb"
      when: not postgres_data.stat.exists
    - name:
      systemd:
        name: postgresql-13
        enabled: yes
        daemon_reload: yes
        state: started

Problem Description:

the following error occurs when running the script:

fatal: [172.17.200.2]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "Failure downloading https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm, Request failed: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)>"}

Solution:

Just modify https to http in https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Read More: