-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpulp_python_repository.yml
105 lines (98 loc) · 4.26 KB
/
pulp_python_repository.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
# Playbook to manage Python package repositories on Pulp
#
# Author: Stefan Joosten <stefan•ɑƬ•atcomputing•ɖɵʈ•nl>
# License: GPLv3
#
- name: Perform management of a Python Package Index on a Pulp repository server
hosts: pulp
force_handlers: true
module_defaults:
pulp.squeezer.status: &pulp_connection_details # & creates YAML anchor
pulp_url: "{{ pulp_url }}" # from group_vars/pulp; for example: http://{{ inventory_hostname }}:8080
username: "{{ pulp_username }}" # from group_vars/pulp
password: "{{ pulp_password }}" # from group_vars/pulp
validate_certs: false
pulp.squeezer.python_distribution:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.python_publication:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.python_repository:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.python_remote:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.python_sync:
<<: *pulp_connection_details # alias to content of pulp_connection_details
vars:
python_repositories:
- name: my_custom_python
description: A place where I can upload my own Python packages
state: present
- name: python_pypi_partial
description: Partial mirror of Python PyPI repository
state: present
remote:
name: pypi
url: https://pypi.org/
policy: immediate
includes: "{{ lookup('file', 'requirements.txt') | split('\n') }}"
tasks:
- name: Refresh and read status from Pulp API # noqa: args[module]
pulp.squeezer.status:
refresh_api_cache: true
- name: Configure Pulp Python repositories # noqa: args[module]
pulp.squeezer.python_repository:
name: "{{ repository.name }}"
description: "{{ repository.description | default(omit) }}"
state: "{{ repository.state | default('present') }}"
loop: "{{ python_repositories }}"
loop_control:
label: "{{ repository.name }}"
loop_var: repository
# The pulp.squeezer.python_distribution does not support the 'repository' option
# it release v0.0.15. I did implement it in my own fork. A PR is forthcoming.
- name: Manage distribution of the repository # noqa: args[module]
pulp.squeezer.python_distribution:
name: "{{ repository.name }}"
base_path: "{{ repository.name }}"
repository: "{{ repository.name }}"
state: "{{ repository.state | default('present') }}"
loop: "{{ python_repositories }}"
loop_control:
label: "{{ repository.name }}"
loop_var: repository
- name: Configure remote Python package index(es) # noqa: args[module]
pulp.squeezer.python_remote:
name: "{{ repository.remote.name }}"
url: "{{ repository.remote.url }}"
policy: "{{ repository.remote.policy | default('on_demand') }}"
state: "{{ repository.state | default('present') }}"
excludes: "{{ repository.remote.excludes | default(omit) }}"
includes: "{{ repository.remote.includes | default(omit) }}"
loop: "{{ python_repositories }}"
loop_control:
label: "{{ repository.remote.name | default('No remote defined for ' + repository.name) }}"
loop_var: repository
when: repository.remote is defined
- name: Synchronize data from remote repositories
pulp.squeezer.python_sync:
repository: "{{ repository.name }}"
remote: "{{ repository.remote.name }}"
register: sync_task
loop: "{{ python_repositories }}"
loop_control:
label: "{{ repository.name }}"
loop_var: repository
when:
- repository.remote is defined
- repository.state is not defined or repository.state == 'present'
ignore_errors: true # when a sync still fails, keep going for any remaining items.
- name: Report synchronised repository version
ansible.builtin.debug:
var: sync.repository_version
verbosity: 1
loop: "{{ sync_task.results }}"
loop_control:
label: "{{ sync.repository.name }}"
loop_var: sync
when: sync.repository_version is defined