Ansible:Failed to synchronize cache for repo 'AppStream', ignoring this repo. Failed to synchronize cache for repo 'BaseOS', ignoring this repo

d1masta94 asked:

I’m new to Ansible, so any advice would be appreciated.
I’m using ansible 2.9.10.

First of all

On my control node, I’ve created a playbook, in which I set up the control host as a repository host: the RHEL 8 installation ISO must be loop mounted on the directory /var/ftp/repo, firewalld service disabled and the vsftpd service is started as well as enabled, and allows anonymous user access to /var/ftp/repo directory

---
- name: Setup control host as repository host
  hosts: localhost
  become: true
  vars:
      anonymous_enable: yes
  tasks:
      - name: Install vsftpd
        yum:
                name: vsftpd
                state: latest

      - name: Start and enable vsftpd service
        service:
                name: vsftpd
                state: started
                enabled: true

      - name: Disable firewall 
        firewalld:
                service: firewall
                state: disabled

      - name: Allow anonymous user access to /var/ftp/repo
        template:
                src: templates/vsftpd.j2/v.j2
                dest: /etc/vsftpd/vsftpd.conf

      - name: Setup repo directory
        file:
                path: /var/ftp/repo
                state: directory

      - name: create repo
        mount:
                path: /var/ftp/repo
                src: /dev/sr0
                fstype: iso9660
                opts: loop,ro
                state: mounted

Next

I have managed node and want to configure it as repository client to the repository server, that was configured above, in previous example. I want to use ad-hoc command to enable access to the BaseOS ans AppStream repositories on my control-node. Below this command and returned result:

[[email protected] ~]$ ansible ansible1 -u root --ask-pass -m yum_repository -a "name=AppStream file=AppStream baseurl=ftp://control.example.com/repo/AppStream/ description=AppStream gpgcheck=no enabled=yes state=present"
SSH password:
 ansible1 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python" 
     },
    "changed": true,
    "repo": "AppStream",
    "state": "present"
     }

[[email protected] ~]$ ansible ansible10 -u root --ask-pass -m yum_repository -a "name=BaseOS file=BaseOS baseurl=ftp://control.example.com/repo/ description=BaseOS gpgcheck=no enabled=yes state=present"

SSH password: 
ansible1 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "repo": "BaseOS",
    "state": "present"

Looks like everything ok, BUT when I’m log in to the managed node and try to do yum repolist, i received:

Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
AppStream                                 0.0  B/s |   0  B     00:01    
BaseOS                                    0.0  B/s |   0  B     00:01    
Failed to synchronize cache for repo 'AppStream', ignoring this repo.
Failed to synchronize cache for repo 'BaseOS', ignoring this repo.

Then I’ve subscribed system with rhel subscription manager, but again when I’m log in to the managed node and try to do yum repolist, I received exactly the same error (in regards of my local repos on control’s node in /var/ftp/repo directory):

Updating Subscription Management repositories.
AppStream                             0.0  B/s |   0  B     00:01    
BaseOS                                0.0  B/s |   0  B     00:01    
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)  3.2 kB/s | 4.5 kB     00:01    
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)  2.8 kB/s | 4.1 kB     00:01    
Failed to synchronize cache for repo 'AppStream', ignoring this repo.
Failed to synchronize cache for repo 'BaseOS', ignoring this repo.
repo id                               repo name                                                                    status
rhel-8-for-x86_64-appstream-rpms   Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)                       10,766
rhel-8-for-x86_64-baseos-rpms      Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)                          4,834   

I need to use my local repo in /var/ftp/repo,please help me to understand where I was wrong! Also, when I tried to install some pkg using ad-hoc command I receive an error:

[[email protected] ~]$ ansible ansible1 -u root --ask-pass -m yum -a "name=httpd state=latest"
SSH password: 
ansible1 | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "failures": [
        "No package httpd available."
    ],
    "msg": "Failed to install some of the specified packages",
    "rc": 1,
    "results": []

My answer:


You cannot install packages until you have subscribed the system and obtained an entitlement.

You can do this with the redhat_subscription module. After it is registered, you can use the rhsm_repository module to enable the repositories you want.

Here is how I register my RHEL systems and enable my desired RHEL repositories:

---
- hosts: all
  gather_facts: True
  tasks:
  - name: "Group by operating system"
    group_by:
      key: os_{{ ansible_distribution }}

- hosts: os_RedHat
  gather_facts: True
  # Registering the system and enabling repos must come first,
  # before installing packages
  pre_tasks:
    - block:
      - name: Register RHEL system
        redhat_subscription:
          activationkey: "Ansible_Provisioned"
          org_id: "*******"
          auto_attach: True
      - name: Enable RHEL repos (RHEL 7)
        rhsm_repository: name={{item}} state=enabled
        with_items:
          - rhel-{{ansible_distribution_major_version}}-server-rpms
          - rhel-{{ansible_distribution_major_version}}-server-extras-rpms
          - rhel-{{ansible_distribution_major_version}}-server-optional-rpms
        when: ansible_distribution_major_version|int <= 7
      - name: Enable RHEL repos (RHEL 8)
        rhsm_repository: name={{item}} state=enabled
        with_items:
          - rhel-{{ansible_distribution_major_version}}-for-{{ansible_architecture}}-baseos-rpms
          - rhel-{{ansible_distribution_major_version}}-for-{{ansible_architecture}}-appstream-rpms
          - rhel-{{ansible_distribution_major_version}}-for-{{ansible_architecture}}-supplementary-rpms
          - codeready-builder-for-rhel-{{ansible_distribution_major_version}}-{{ansible_architecture}}-rpms
        when: ansible_distribution_major_version|int == 8
      - name: Disable RHEL repos (RHEL 7)
        rhsm_repository: name={{item}} state=disabled
        with_items:
          - rhel-{{ansible_distribution_major_version}}-server-rt-rpms
          - rhel-{{ansible_distribution_major_version}}-server-rt-beta-rpms
        when: ansible_distribution_major_version|int <= 7
      when: ansible_distribution == 'RedHat'
  roles:
    - redhatinsights.insights-client

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.