Bram
Bram

Reputation: 825

How to test a role with molecule that uses the rhsm_repository module?

One of my ansible roles calls the rhsm_repository module:

- name: Enable Red Hat Software Collections repo
  rhsm_repository:
    name: rhel-server-rhscl-7-rpms
  when: ( ansible_os_family == "RedHat" and ansible_facts['distribution_major_version'] == "7")

I am adding molecule testing to the role but the converge step fails to enable the repository:

TASK [mariadb : Enable Red Hat Software Collections repo]
*********************************************************
fatal: [rhel7]: FAILED! => {"changed": false, "msg": "rhel-server-rhscl-7-rpms is not a valid repository ID", "results": ["rhel-server-rhscl-7-rpms is not a valid repository ID"]}

Running the subscription-manager command in the container fails as well. subscription-manager is the command used by this module AFAICT.

[root@rhel7 /]# subscription-manager status
subscription-manager is disabled when running inside a container. Please refer to your host system for subscription management.

My host is a RHEL8 so I can't enable the repo even if I wanted to. But the idea of using molecule is to allow testing various distros so that seems like the wrong approach anyway.

How can I test the rhsm_repository module with molecule in podman containers?

The platform definition of my molecule is:

  - name: rhel7                                    
    image: registry.access.redhat.com/ubi7/ubi-init
    command: "/usr/sbin/init"                      
    tmpfs:                                         
      - /run                                       
      - /tmp                                       
    pre_build_image: true                          

Upvotes: 1

Views: 363

Answers (1)

Zeitounator
Zeitounator

Reputation: 44615

This obviously cannot be tested inside a container so forget podman or docker for this one.

You would have to use a molecule driver plugin such as (non exhaustive list) molecule-vmware, molecule-vagrant, molecule-openstack... which will let you spin-up an actual vm running the mandatory OS to use and test that module.

For a list of (mainly only...) community plugins for molecule, see list of projects matching "molecule" on ansible-community's github

Upvotes: 1

Related Questions