Create a Simple Software Repository for Ansible

This guide demonstrates how to establish a straightforward software repository with Ansible, which will serve as a centralized source for software distribution.

Projects: c2platform/rws/ansible-gis, c2platform.core, c2platform.wincore, c2platform.mw


Overview

This guide outlines the process adopted by RWS for managing software downloads using Ansible. It follows the strategy described in Designing a Flexible Software Repository for Ansible and employs the c2platform.wincore.download role for download operations. The setup involves Vagrant and Ansible executing the following tasks:

  1. Vagrant employs the VirtualBox Provider to instantiate five VMs as specified in the table below.
  2. Using the Ansible Provisioner, Vagrant orchestrates an Ansible playbook across these VMs to:
    1. Establish a Windows File Share on gsd-ansible-file-share1, populating it with a Tomcat tarball and a zip file.
    2. Set up a software service, gsd-ansible-repo, which mounts the file share and hosts its contents via Apache2.
    3. Initiate concurrent downloads on three nodes (gsd-ansible-download1, gsd-ansible-download2, gsd-ansible-download3), using HTTPS. Shared storage acts as a cache, facilitated by gsd-ansible-file-share1. The c2platform.wincore.download role ensures that downloads are synchronized, with only one node downloading a file at any given time, determined by which node acquires a lock file first. There are two downloads, potentially handled by different nodes.
NodeOSProviderPurpose
gsd-ansible-file-share1Windows 2022 ServerVirtualBoxHosts file share for storing and caching downloads
gsd-ansible-repoRed Hat 9VirtualBoxSimple web-based software server using Apache2
gsd-ansible-download1Windows 2022 ServerVirtualBoxExecutes test downloads
gsd-ansible-download2Windows 2022 ServerVirtualBoxExecutes test downloads
gsd-ansible-download3Windows 2022 ServerVirtualBoxExecutes test downloads

Prerequisites

  • Ensure your RWS Development Environment is set up on Ubuntu 22, as detailed here.

Setup

To prepare the complete environment, execute vagrant up for the specified VMs. On a high-performance development workstation, this setup should take approximately 25 minutes.

export BOX="gsd-ansible-repo gsd-ansible-file-share1 gsd-ansible-download1 \
gsd-ansible-download2 gsd-ansible-download3"
vagrant up $BOX

Verification

  1. Successful execution of the playbook indicates that the download nodes (gsd-ansible-download1, gsd-ansible-download2, gsd-ansible-download3) managed to retrieve the Tomcat binaries. Review the final console output from Ansible, highlighting tasks like tasks Create download lock, Download install file, Extract zip and Remove lock file, to determine which node successfully acquired the lock and completed the download.

    Show me

    TASK [c2platform.wincore.download : Create download lock] **********************
    changed: [gsd-ansible-download1] => (item=//gsd-ansible-file-share1.internal.c2platform.org/ansible-repo/cache\apache-tomcat-10.1.19.tar.gz)
    ok: [gsd-ansible-download2] => (item=//gsd-ansible-file-share1.internal.c2platform.org/ansible-repo/cache\apache-tomcat-10.1.19.tar.gz)
    ok: [gsd-ansible-download3] => (item=//gsd-ansible-file-share1.internal.c2platform.org/ansible-repo/cache\apache-tomcat-10.1.19.tar.gz)
    changed: [gsd-ansible-download1] => (item=//gsd-ansible-file-share1.internal.c2platform.org/ansible-repo/cache\apache-tomcat-10.1.19.zip)
    ok: [gsd-ansible-download2] => (item=//gsd-ansible-file-share1.internal.c2platform.org/ansible-repo/cache\apache-tomcat-10.1.19.zip)
    ok: [gsd-ansible-download3] => (item=//gsd-ansible-file-share1.internal.c2platform.org/ansible-repo/cache\apache-tomcat-10.1.19.zip)
    
    TASK [c2platform.wincore.download : Download install file] *********************
    changed: [gsd-ansible-download1] => (item=//gsd-ansible-file-share1.internal.c2platform.org/ansible-repo/cache\apache-tomcat-10.1.19.tar.gz)
    changed: [gsd-ansible-download1] => (item=//gsd-ansible-file-share1.internal.c2platform.org/ansible-repo/cache\apache-tomcat-10.1.19.zip)
    
    TASK [c2platform.wincore.download : Extract zip] *******************************
    changed: [gsd-ansible-download1] => (item=apache-tomcat-10.1.19.zip → //gsd-ansible-file-share1.internal.c2platform.org/ansible-repo/cache\apache-tomcat-10.1.19)
    
    TASK [c2platform.wincore.download : Remove lock file] **************************
    changed: [gsd-ansible-download1] => (item=\\gsd-ansible-file-share1.internal.c2platform.org\ansible-repo\cache\e9e4e25175d60ab7bf720609971f81206c644ce950deed17bf6de78613cca091.lock → absent)
    changed: [gsd-ansible-download1] => (item=\\gsd-ansible-file-share1.internal.c2platform.org\ansible-repo\cache\4c6082b852ad235cb10bc50992259ddc1145664c6347b0ea97100cada66c5153.lock → absent)
    

  2. Using the RWS FireFox profile navigate to https://gsd-ansible-repo.internal.c2platform.org/  . When prompted, log in with the username ansible and the password Supersecret!. You should be able to view and download the Tomcat binaries, such as apache-tomcat-10.1.19.tar.gz.

  3. Access gsd-ansible-download1 via Remmina or VirtualBox Manager as the vagrant user (password: vagrant). Desktop shortcuts provide links to the file share and downloads. The vagrant user has full control over and access to the share.

Review

To understand the VM setup and configuration, review the Ansible Inventory and Vagrant project files, and the Ansible collections.

Ansible Inventory

Review the following files in the Ansible inventory / Vagrant project c2platform/rws/ansible-gis:

File(s)Description
Vagrantfile and Vagrantfile.ymlUsed by Vagrant for VM creation, network setup, etc.
plays/mgmt/ansible_repo.ymlThe primary Ansible playbook
group_vars/ansible_file_share/*Configuration for the file share node gsd-ansible-file-share1
group_vars/ansible_repo/*Configuration for the web server node gsd-ansible-repo
group_vars/ansible_download/*Configuration for the download nodes gsd-ansible-download1, 2 and 3

Ansible Collections / Roles

CollectionDescription
c2platform.wincoreIncludes essential roles for Windows hosts, such as c2platform.wincore.download.
c2platform.coreProvides roles for Linux targets, e.g., c2platform.core.linux.
c2platform.mwContains the apache role for web server setup.

Next Steps

For development and experimentation, consider a stepwise approach using Ansible tags and Vagrant snapshots to manage and iterate on the environment more efficiently.

Show me

TagStepCommandDescription
v0Create File ShareTAGS=v0 vagrant up $BOXCreates all nodes but only runs the Ansible provisioner on gsd-ansible-file-share1.
v1Create Web ServerTAGS=v1 vagrant provision $BOXRun the provisioner on gsd-ansible-repo. This creates the Apache2 based web server.
v2Download softwareTAGS=v2 vagrant provision $BOXRuns Ansible on gsd-ansible-download[1:3]

To provision a specific tag you just prefix the command with TAGS= for example to provision step v1 run the command:

TAGS=v1 vagrant provision $BOX

After each step you can create snapshots using Vagrant. Especially a snapshot after v0 because node creation takes some time. This also includes registration of the RHEL 9 based gsd-ansible-repo and Sysprep of all Windows hosts.

There are other tags so for example if you only want to perform only the download and only from gsd-ansible-download1

TAGS=common,download vagrant up $BOX --provision | tee provision.log

Additional Information

For additional insights and guidance:



Last modified November 13, 2024: translate false C2-587 (af41e45)