Develop a private collection

Learn how to develop a private collection that provisions a KVM guest on an IBM Z and LinuxONE LPAR.


Detailed diagram of private network
  1. Create and cd to this directory structure (this structure is required for the Ansible sanity checking later):

    mkdir -p ansible_collections/example
    cd ansible_collections/example
  2. Download the sample collection from here. Rename the folder to rhel_kvm_roles:

    git clone https://github.com/ansible-collections/collection_template.git
    # renaming the folder to rhel_kvm_roles:
    mv collection_template rhel_kvm_roles
    cd rhel_kvm_roles
  3. Edit galaxy.yml.

    • Change namespace to: example

    • Change name to: rhel_kvm_roles

    • Add a few tags, so people can search for collections

    Note: For proof of concept and demo purposes no further changes are made.
    # See https://docs.ansible.com/ansible/latest/dev_guide/collections_galaxy_meta.html
    
    namespace: example
    name: rhel_kvm_roles
    version: 0.1.0
    readme: README.md
    authors:
      - YOUR NAME (github.com/YOURGITHUB)
    description: null
    license_file: LICENSE
    tags:
    # tags so people can search for collections https://galaxy.ansible.com/search
    # tags are all lower-case, no spaces, no dashes.
      - libvirt
      - kvm
      - provisioning
      - provision
    repository: https://github.com/ansible-collections/community.REPO_NAME
    #documentation: https://github.com/ansible-collection-migration/community.REPO_NAME/tree/main/docs
    homepage: https://github.com/ansible-collections/community.REPO_NAME
    issues: https://github.com/ansible-collections/community.REPO_NAME/issues
    build_ignore:
    # https://docs.ansible.com/ansible/devel/dev_guide/developing_collections_distributing.html#ignoring-files-and-folders
      - .gitignore
      - changelogs/.plugin-cache.yaml
  4. Create a new folder called roles. Download and unpack guest_install.zip into that directory.

    mkdir roles
    cd roles
    curl https://www.ibm.com/docs/en/linuxonibm/pdf/guest_install.zip
    unzip guest_install.zip
    rm guest_install.zip
  5. Go to the rhel_kvm_roles folder and run the sanity check:

    cd ..
    ansible-test sanity
  6. Build the collection tarball:

    ansible-galaxy collection build

    Expected output:

    Created collection for example.rhel_kvm_roles at /path/to/rhel_kvm_roles/example-rhel_kvm_roles-0.1.0.tar.gz

Upload to private automation hub

  1. Go to Collections -> Namespaces. Click Create to create a namespace, and name it example:


    Create a namespace menu

    Create a new namespace dialog
    Note: You can also use any existing namespace.
  2. In the example namespace, click upload collection:


    Upload a collection menu
  3. Select the collection tarball. Click upload:


    Upload a new collection selection
  4. After the import is complete, the collection resides in the repository Staging. By default, there is a pipeline defined that you can use to test the collections before they are published to the Published repository. To move the collection from Staging to Published, click Collections -> Approval:


    Upload a new collection select approval
  5. In the Approval dashboard, click approve to move the collection from the staging repository to the published repository:


    Upload a new collection approval dashboard

For future uploads you can also use the following command as described here:

ansible-galaxy collection publish path/to/my_namespace-my_collection-1.0.0.tar.gz --api-key=SECRET

To use this collection directly from the Ansible Automation Controller (AAC) continue with running a playbook.

If you want to use the collection from a command line interface (CLI), go to the published repository (Collections -> Repositories -> published), click Copy CLI configuration and place the information in /etc/ansible.cfg on the system that needs access to this collection:


Collection published confirmation screen

To learn more about the CLI, have a look at Configuring Red Hat Automation Hub as the primary source for content.