-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpulp_file_repo_from_fileglob.yml
127 lines (115 loc) · 5.15 KB
/
pulp_file_repo_from_fileglob.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
---
# This playbook attempts to ensure and populate a File repository in Pulp.
# Author: Stefan Joosten <stefan•ɑƬ•atcomputing•ɖɵʈ•nl>
# License: GPLv3
#
# This playbook requires a (valid) repository name to be set (as value of file_repository_name).
# For example by running it as follows:
#
# $ ansible-playbook \
# --extra-vars 'file_repository_name=my_own_repository' \
# pulp_file_repo_from_fileglob.yml
#
# Or by being called from another playbook.
#
# Other optional variables are:
# file_repository_description: "a description for the repository"
# file_local_upload_path: "local path where to look for files"
#
- name: Upload a local file(s) to a file repository on Pulp
hosts: localhost
connection: local
force_handlers: true
module_defaults: # saves specifying these settings at every task using these modules
pulp.squeezer.status: &pulp_connection_details # & creates YAML anchor
pulp_url: "{{ pulp_url }}" # from group_vars/pulp; example: http://{{ inventory_hostname }}:8080
username: "{{ pulp_username }}" # from group_vars/pulp
password: "{{ pulp_password }}" # from group_vars/pulp
validate_certs: false
pulp.squeezer.artifact:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.file_content:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.file_repository:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.file_publication:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.file_distribution:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.task:
<<: *pulp_connection_details # alias to content of pulp_connection_details
ansible.builtin.uri:
body_format: json
force_basic_auth: true
url_username: "{{ pulp_username }}" # from group_vars/pulp
url_password: "{{ pulp_password }}" # from group_vars/pulp
validate_certs: false
vars:
# Pulp where?
#pulp_url: "http://{{ inventory_hostname }}:8080" # specified in from group_vars/pulp already
# Name and description of repository to put the packages in
#file_repository_name: my_very_own_repository # disabled to prevent this from running as-is.
file_repository_description: "My repository for Aiur!"
# Local path, on control node, where to look for files to upload for this repository.
file_local_upload_path: "{{ playbook_dir }}/upload/{{ file_repository_name }}"
tasks:
- name: Stop when no file_repository_name given
ansible.builtin.fail:
msg: "Bailing out. The play requires a repository name set in variable 'file_repository_name'."
when: file_repository_name is undefined
- name: Acquire details of local file(s)
ansible.builtin.stat:
path: "{{ item }}" # point me to a real file, not a symlink
checksum_algorithm: sha256
get_mime: true
register: file
loop: "{{ query('ansible.builtin.fileglob', file_local_upload_path + '/*') }}"
delegate_to: localhost
- name: Bail out when no matching files are found
ansible.builtin.fail:
msg: |
No matching files have been found in path:
{{ file_local_upload_path }}/*.file
when: file.results | length < 1
- name: Verify file(s) to upload are readable files
ansible.builtin.assert:
that:
- item.stat.readable
- not item.stat.islnk
- item.stat.checksum | length > 0
fail_msg: |
Something went wrong during verification of file '{{ item.stat.path }}'.
Please make sure this path is readable, is not a symlink and is a proper file.
quiet: true
loop: "{{ file.results }}"
loop_control:
label: "{{ item.stat.path }}"
delegate_to: localhost
- name: Refresh and read status from Pulp API # noqa: args[module]
pulp.squeezer.status:
refresh_api_cache: true
- name: Ensure file repository # noqa: args[module]
pulp.squeezer.file_repository:
name: "{{ file_repository_name }}"
description: "{{ file_repository_description }}"
state: present
- name: Ensure artifact present as file content # noqa: args[module]
pulp.squeezer.file_content:
file: "{{ item.stat.path }}"
repository: "{{ file_repository_name }}"
relative_path: "{{ item.stat.path | basename }}"
state: present
loop: "{{ file.results }}"
loop_control:
label: "{{ item.stat.path }}"
- name: Create a publication of last repository version # noqa: args[module]
pulp.squeezer.file_publication:
repository: "{{ file_repository_name }}"
state: present
register: file_publication
- name: Distribute the publication to make repo content available # noqa: args[module]
pulp.squeezer.file_distribution:
name: "{{ file_repository_name }}"
base_path: "{{ file_repository_name }}"
publication: "{{ file_publication.publication.pulp_href }}"
state: present