Skip to content

Commit

Permalink
update repository
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-m-sullivan committed Aug 24, 2023
1 parent 8263fe5 commit 7758a92
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
- stable-4.4
- stable-4.5
- stable-4.6
# - master disabled until build issue resolved
- stable-4.7
- master
uses: "./.github/workflows/ci_standalone_versioned.yml"
with:
galaxy_ng_version: ${{ matrix.galaxy_ng_version }}
Expand Down
1 change: 1 addition & 0 deletions bindep.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python >=3.5
5 changes: 3 additions & 2 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ description: Ansible content that interacts with the Ansible Automation Hub or G
documentation: https://github.com/ansible/galaxy_collection/blob/devel/README.md
license:
- GPL-3.0-only
namespace: galaxy
name: galaxy
namespace: infra
name: ah_configuration
version: 1.1.1-devel
readme: README.md
repository: https://github.com/ansible/galaxy_collection
Expand All @@ -27,4 +27,5 @@ build_ignore:
- galaxy.yml.j2
- template_galaxy.yml
- '*.tar.gz'
- test
...
14 changes: 8 additions & 6 deletions plugins/modules/collection_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
description:
- Existing remote name.
type: str
update:
update_repo:
description:
- Whether to update the collection repository before exiting the module.
required: false
Expand Down Expand Up @@ -155,7 +155,7 @@ def main():
pulp_labels=dict(type="dict"),
private=dict(type="bool", default=False),
remote=dict(),
update=dict(default=False, type="bool"),
update_repo=dict(type="bool", default=False),
wait=dict(default=True, type="bool"),
interval=dict(default=1.0, type="float"),
timeout=dict(default=None, type="int"),
Expand All @@ -167,7 +167,7 @@ def main():
# Extract our parameters
name = module.params.get("name")
module.fail_on_missing_params(["name"])
update = module.params.get("wait")
update_repo = module.params.get("update_repo")
wait = module.params.get("wait")
interval = module.params.get("interval")
timeout = module.params.get("timeout")
Expand Down Expand Up @@ -196,7 +196,8 @@ def main():
ansible_repository = AHPulpAnsibleRepository(module)
ansible_repository.get_object(name=name)

if distro := new_fields.get("distribution"):
distro = new_fields.get("distribution")
if distro:
# if "distribution" is set, but "state" is missing, set "present"
distro_state = distro.get("state", None)

Expand Down Expand Up @@ -224,7 +225,8 @@ def main():

ansible_repository.delete(auto_exit=True)

if remote := new_fields.get("remote"):
remote = new_fields.get("remote")
if remote:
ansible_remote = AHPulpAnsibleRemote(module)
ansible_remote.get_object(name=remote)

Expand Down Expand Up @@ -262,7 +264,7 @@ def main():
auto_exit=False,
)

if update:
if update_repo:
ansible_repository.sync(wait, interval, timeout)

module.exit_json(**module.json_output)
Expand Down
2 changes: 1 addition & 1 deletion roles/collection_repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ This also speeds up the overall role.
|`distribution`|""|no|dict|Distribution options for the collection repository. See additional options below for details. Most users will leave this blank|
|`private`|""|no|boolean|Make the Collection repository private.|
|`remote`|""|no|str|Remote repository name. This is used if the collections use a remote source.|
|`update`|`false`|no|bool|Wait for the Collection repository to finish syncing before returning.||
|`update_repo`|`false`|no|bool|Wait for the Collection repository to finish syncing before returning.||
|`wait`|`true`|no|bool|Wait for the Collection repository to finish syncing before returning.||
|`interval`|1.0|no|float|The interval to request an update from Automation Hub.||
|`timeout`|""|no|int|If waiting for the project to update this will abort after this amount of seconds.||
Expand Down
8 changes: 4 additions & 4 deletions roles/collection_repository/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
distribution: "{{ __collection_repository_item.distribution | default(omit) }}"
private: "{{ __collection_repository_item.private | default(omit) }}"
remote: "{{ __collection_repository_item.remote | default(omit) }}"
update: "{{ __repository_item.update | default(omit) }}"
wait: "{{ __repository_item.wait | default(omit) }}"
interval: "{{ __repository_item.interval | default(1) }}"
timeout: "{{ __repository_item.timeout | default(omit) }}"
update_repo: "{{ __collection_repository_item.update_repo | default(omit) }}"
wait: "{{ __collection_repository_item.wait | default(omit) }}"
interval: "{{ __collection_repository_item.interval | default(1) }}"
timeout: "{{ __collection_repository_item.timeout | default(omit) }}"
state: "{{ __collection_repository_item.state | default(ah_state | default('present')) }}"
ah_host: "{{ ah_host | default(ah_hostname) }}"
ah_username: "{{ ah_username | default(omit) }}"
Expand Down
6 changes: 3 additions & 3 deletions roles/collection_repository_sync/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
- name: Sync Automation Hub Collection Remote repository
collection_repository_sync:
name: "{{ __collection_repository_sync_item.name }}"
wait: "{{ __repository_item.wait | default(omit) }}"
interval: "{{ __repository_item.interval | default(1) }}"
timeout: "{{ __repository_item.timeout | default(omit) }}"
wait: "{{ __collection_repository_sync_item.wait | default(omit) }}"
interval: "{{ __collection_repository_sync_item.interval | default(1) }}"
timeout: "{{ __collection_repository_sync_item.timeout | default(omit) }}"
ah_host: "{{ ah_host | default(ah_hostname) }}"
ah_username: "{{ ah_username | default(omit) }}"
ah_password: "{{ ah_password | default(omit) }}"
Expand Down
6 changes: 6 additions & 0 deletions tests/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# See template for more information:
# https://github.com/ansible/ansible/blob/devel/test/lib/ansible_test/config/config.yml
modules:
python_requires: '>=3.5'
...
13 changes: 13 additions & 0 deletions tests/playbooks/ah_configs/ah_repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,17 @@ ah_collection_repositories:
distribution:
state: present
remote: community-infra
- name: community-infra-repo-nodistro
description: "description of community-infra repository"
pulp_labels:
pipeline: "approved"
remote: community-infra
- name: community-infra-repo-noremote
description: "description of community-infra repository"
pulp_labels:
pipeline: "approved"
distribution:
state: present
- name: community-infra-repo-nothing
description: "description of community-infra repository"
...
5 changes: 4 additions & 1 deletion tests/playbooks/testing_collections_repos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
connection: local
gather_facts: false
collections:
- ansible.automation_hub
- infra.ah_configuration
pre_tasks:
- name: Include vars from ah_configs directory
ansible.builtin.include_vars:
Expand Down Expand Up @@ -61,4 +61,7 @@
- name: Collection Repository sync
ansible.builtin.include_role:
name: collection_repository_sync
vars:
ah_collection_repositories:
- name: community-infra-repo
...

0 comments on commit 7758a92

Please sign in to comment.