Ansible playbook to select multiple repository in a single execution

Problem:
I am not able to select multiple repository of alma linux 8.3 version.
Expected outcome:
Outcome is to select the multiple repository through playbook
Foreman and Proxy versions:
2.2.5
Distribution and version:
RHEL 7.9
Other relevant data:
This is my playbook

- hosts: foreman
  vars_prompt:
    - name: "Product"
      prompt: "Which Product Do you want to install?"
      private: "No"
  tasks:
    - name: "Create product with a sync plan"
      theforeman.foreman.product:
        username: "admin"
        password: "admin"
        server_url: "https://ingbtcpic6vl232.code1.emi.com/"
        name: "{{ Product }}"
        organization: "Test Organization"
        state: present

    - name: "Create repository"
      theforeman.foreman.repository:
        username: "admin"
        password: "admin"
        server_url: "https://ingbtcpic6vl232.code1.emi.com/"
        name: "AppStream"
        state: present
        content_type: "yum"
        product: "{{ Product }}"
        organization: "Test Organization"
        url: "https://repo.almalinux.org/almalinux/8.3/"

That alma linux link contains multiple repositories


I am trying to select Appstream, BaseOS and extras. Is there any possible ways to do that rather than defining each of the links in playbook? Any automated approach is possible, like by providing input saying AppStream, BaseOS and extras are needed in Alma Linux 8.3 product?

There is currently no way, you’ll have to do this manually, like this:

    - name: "Create repository"
      theforeman.foreman.repository:
        username: "admin"
        password: "admin"
        server_url: "https://ingbtcpic6vl232.code1.emi.com/"
        name: "{{ item }}"
        state: present
        content_type: "yum"
        product: "{{ Product }}"
        organization: "Test Organization"
        url: "https://repo.almalinux.org/almalinux/8.3/{{ item }}"
      loop:
        - BaseOS
        - AppStream
1 Like

Thanks. Is there any ansible roles for this?

We do have a repositories role, have a look here: theforeman.foreman.repositories — Foreman Ansible Modules documentation

1 Like

@evgeni How can we automate adding GPG key?

https://theforeman.github.io/foreman-ansible-modules/develop/plugins/content_credential_module.html#ansible-collections-theforeman-foreman-content-credential-module

@evgeni Yes, this I saw. I mean, Is there any way ansible can fetch the gpg key directly from Index of /almalinux/8.3/ ?

https://docs.ansible.com/ansible/2.9/plugins/lookup/url.html