From cf797cfa41cf3690ba45d4eabcc3ed4776adb2f4 Mon Sep 17 00:00:00 2001 From: Orion Poplawski Date: Mar 12 2021 19:50:44 +0000 Subject: Add rpm macros and generators for collections --- diff --git a/ansible-generator b/ansible-generator new file mode 100755 index 0000000..b7450b1 --- /dev/null +++ b/ansible-generator @@ -0,0 +1,46 @@ +#!/usr/bin/python3 + +import argparse +import json +import re +import sys + + +def main(): + parser = argparse.ArgumentParser() + group = parser.add_mutually_exclusive_group(required=True) + group.add_argument( + "-P", "--provides", action="store_const", const="provides", dest="action" + ) + group.add_argument( + "-R", "--requires", action="store_const", const="requires", dest="action" + ) + args = parser.parse_args() + + files = sys.stdin.read().splitlines() + + for f in files: + with open(f, "r") as fobj: + info = json.load(fobj)["collection_info"] + if args.action == "provides": + print( + f"ansible-collection({info['namespace']}.{info['name']}) = {info['version']}" + ) + if args.action == "requires": + print("(ansible >= 2.9.0 or ansible-base > 2.10.0)") + for dep, req in info.get("dependencies", {}).items(): + print(f"ansible-collection({dep})", end="") + if req == "*": + print() + continue + m = re.match(r"^>=(\d+\.\d+\.\d+)$", req) + if m: + print(f" >= {m.group(1)}") + continue + raise NotImplementedError( + "Generation of dependencies different than '*' or '>=' is not supported yet" + ) + + +if __name__ == "__main__": + main() diff --git a/ansible.attr b/ansible.attr new file mode 100644 index 0000000..997dafa --- /dev/null +++ b/ansible.attr @@ -0,0 +1,3 @@ +%__ansible_provides %{_rpmconfigdir}/ansible-generator --provides +%__ansible_requires %{_rpmconfigdir}/ansible-generator --requires +%__ansible_path ^%{_datadir}/ansible/collections/ansible_collections/[^/]+/[^/]+/MANIFEST.json$ diff --git a/ansible.spec b/ansible.spec index 780f783..e2dbb58 100644 --- a/ansible.spec +++ b/ansible.spec @@ -19,10 +19,13 @@ Name: ansible Summary: SSH-based configuration management, deployment, and task execution system Version: 2.9.18 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv3+ Source0: https://releases.ansible.com/ansible/%{name}-%{version}.tar.gz +Source1: ansible.attr +Source2: ansible-generator +Source3: macros.ansible Url: http://ansible.com BuildArch: noarch @@ -123,6 +126,7 @@ This package installs extensive documentation for ansible %prep %autosetup -p1 -n %{name}-%{version} +cp -a %{S:1} %{S:2} %{S:3} . %build @@ -194,6 +198,10 @@ cp -pr docs/docsite/rst . cp -pr docs/docsite/_build/html %{_builddir}/%{name}-%{version}/html %endif +install -Dpm0644 -t %{buildroot}%{_fileattrsdir} ansible.attr +install -Dpm0644 -t %{buildroot}%{_rpmmacrodir} macros.ansible +install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} ansible-generator + %check %if 0%{?with_tests} @@ -214,6 +222,9 @@ make PYTHON=/usr/bin/python3 tests-py3 %{python3_sitelib}/ansible %{python3_sitelib}/ansible_test %{python3_sitelib}/*egg-info +%{_fileattrsdir}/ansible.attr +%{_rpmmacrodir}/macros.ansible +%{_rpmconfigdir}/ansible-generator %files -n ansible-doc %doc rst @@ -222,6 +233,9 @@ make PYTHON=/usr/bin/python3 tests-py3 %endif %changelog +* Fri Mar 12 2021 Orion Poplawski - 2.9.18-2 +- Add rpm macros and generators for collections + * Sat Feb 20 2021 Kevin Fenzi - 2.9.18-1 - Update to 2.9.18. - Fixes: CVE-2021-20228 CVE-2021-20178 CVE-2021-20180 CVE-2021-20191 diff --git a/macros.ansible b/macros.ansible new file mode 100644 index 0000000..c8c91fb --- /dev/null +++ b/macros.ansible @@ -0,0 +1,7 @@ +%ansible_collection_url() https://galaxy.ansible.com/%{collection_namespace}/%{collection_name} + +%ansible_collection_build() ansible-galaxy collection build + +%ansible_collection_install() ansible-galaxy collection install -n -p %{buildroot}%{_datadir}/ansible/collections %{collection_namespace}-%{collection_name}-%{version}.tar.gz + +%ansible_collection_files %{_datadir}/ansible/collections/ansible_collections/%{collection_namespace}/