From 040d95c519a51cb45bc5a202d0c5ad54c4b8fd15 Mon Sep 17 00:00:00 2001 From: Thomas Woerner <twoerner@redhat.com> Date: Tue, 23 Jul 2019 09:48:30 +0200 Subject: [PATCH] utils/build-galaxy-release.sh: New build script for galaxy release This script will to the following steps: - Fix the galaxy release in galaxy.yml - Remove emacs backup files - Link module_utils, modules and action_plugins from roles to plugins/.. - Fix import prefix for module_utils - Fix module prefixes in playbooks and example playbooks - Build release using mazer - Clean up again --- utils/build-galaxy-release.sh | 46 +++++++++++++++++++++++++++++++++++ utils/galaxyify-playbook.py | 39 +++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 utils/build-galaxy-release.sh create mode 100644 utils/galaxyify-playbook.py diff --git a/utils/build-galaxy-release.sh b/utils/build-galaxy-release.sh new file mode 100644 index 00000000..c5ca3378 --- /dev/null +++ b/utils/build-galaxy-release.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +galaxy_version=$(git describe --tags | sed -e "s/^v//") +echo $galaxy_version | grep "-" -q || galaxy_version="${galaxy_version}-1" +sed -i -e "s/version: .*/version: \"$galaxy_version\"/" galaxy.yml + +find . -name "*~" -exec rm {} \; + +sed -i -e "s/ansible.module_utils.ansible_freeipa_module/ansible_collections.freeipa.ansible_freeipa.plugins.module_utils.ansible_freeipa_module/" *.py + +cd plugins/module_utils && { + ln -s ../../roles/ipa*/module_utils/*.py . + cd ../.. +} + +cd plugins/modules && { + sed -i -e "s/ansible.module_utils.ansible_ipa_/ansible_collections.freeipa.ansible_freeipa.plugins.module_utils.ansible_ipa_/" ../../roles/ipa*/library/*.py + ln -s ../../roles/ipa*/library/*.py . + cd ../.. +} + +[ ! -x plugins/action_plugins ] && mkdir plugins/action_plugins +cd plugins/action_plugins && { + ln -s ../../roles/ipa*/action_plugins/*.py . + cd ../.. +} + +for x in roles/ipa*/tasks/*.yml; do + python utils/galaxyify-playbook.py "$x" +done + +for x in $(find playbooks -name "*.yml" -print); do + python utils/galaxyify-playbook.py "$x" +done + +#git diff + +mazer build + +rm plugins/module_utils/ansible_ipa_* +rm plugins/modules/ipaserver_* +rm plugins/modules/ipareplica_* +rm plugins/modules/ipaclient_* +rm plugins/action_plugins/ipaclient_* +git reset --hard + diff --git a/utils/galaxyify-playbook.py b/utils/galaxyify-playbook.py new file mode 100644 index 00000000..e23c347e --- /dev/null +++ b/utils/galaxyify-playbook.py @@ -0,0 +1,39 @@ +import os +import sys +import re + +def galaxify_playbook(playbook_in): + p1 = re.compile('(ipa.*:)$') + p2 = re.compile('(name:) (ipa.*)$') + lines = [ ] + + with open(playbook_in) as in_f: + changed = False + changeable = False + include_role = False + for line in in_f: + stripped = line.strip() + if stripped.startswith("- name:") or \ + stripped.startswith("- block:"): + changeable = True + elif stripped in [ "set_fact:", "vars:" ]: + changeable = False + include_role = False + elif stripped.startswith("include_role:"): + include_role = True + elif include_role and stripped.startswith("name:"): + line = p2.sub(r'\1 freeipa.ansible_freeipa.\2', line) + changed = True + elif changeable and \ + not stripped.startswith("freeipa.ansible_freeipa."): + line = p1.sub(r'freeipa.ansible_freeipa.\1', line) + changed = True + + lines.append(line) + + if changed: + with open(playbook_in, "w") as out_f: + for line in lines: + out_f.write(line) + +galaxify_playbook(sys.argv[1]) -- GitLab