Skip to content
Snippets Groups Projects
Commit 57d407f1 authored by Thomas Woerner's avatar Thomas Woerner
Browse files

utils/*galaxy*: Make galaxy scripts more generic

The namespace and colleciton name have been hard coded. Now variables are
used for them. The project prefix and collection prefix are now passed to
galaxyify-playbook.py.
parent cd5429a5
Branches
Tags
No related merge requests found
#!/bin/bash #!/bin/bash
namespace="freeipa"
collection="ansible_freeipa"
collection_prefix="${namespace}.${collection}"
galaxy_version=$(git describe --tags | sed -e "s/^v//") galaxy_version=$(git describe --tags | sed -e "s/^v//")
echo $galaxy_version | grep "-" -q || galaxy_version="${galaxy_version}" echo $galaxy_version | grep "-" -q || galaxy_version="${galaxy_version}"
sed -i -e "s/version: .*/version: \"$galaxy_version\"/" galaxy.yml sed -i -e "s/version: .*/version: \"$galaxy_version\"/" galaxy.yml
find . -name "*~" -exec rm {} \; 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/" plugins/modules/*.py sed -i -e "s/ansible.module_utils.ansible_freeipa_module/ansible_collections.${collection_prefix}.plugins.module_utils.ansible_freeipa_module/" plugins/modules/*.py
cd plugins/module_utils && { cd plugins/module_utils && {
ln -s ../../roles/ipa*/module_utils/*.py . ln -s ../../roles/*/module_utils/*.py .
cd ../.. cd ../..
} }
cd plugins/modules && { 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 sed -i -e "s/ansible.module_utils.ansible_ipa_/ansible_collections.${collection_prefix}.plugins.module_utils.ansible_ipa_/" ../../roles/*/library/*.py
ln -s ../../roles/ipa*/library/*.py . ln -s ../../roles/*/library/*.py .
cd ../.. cd ../..
} }
[ ! -x plugins/action_plugins ] && mkdir plugins/action_plugins [ ! -x plugins/action_plugins ] && mkdir plugins/action_plugins
cd plugins/action_plugins && { cd plugins/action_plugins && {
ln -s ../../roles/ipa*/action_plugins/*.py . ln -s ../../roles/*/action_plugins/*.py .
cd ../.. cd ../..
} }
for x in roles/ipa*/tasks/*.yml; do for x in roles/*/tasks/*.yml; do
python utils/galaxyify-playbook.py "$x" python utils/galaxyify-playbook.py "$x" "ipa" "$collection_prefix"
done done
for x in $(find playbooks -name "*.yml" -print); do for x in $(find playbooks -name "*.yml" -print); do
python utils/galaxyify-playbook.py "$x" python utils/galaxyify-playbook.py "$x" "ipa" "$collection_prefix"
done done
#git diff #git diff
...@@ -43,4 +47,3 @@ rm plugins/modules/ipareplica_* ...@@ -43,4 +47,3 @@ rm plugins/modules/ipareplica_*
rm plugins/modules/ipaclient_* rm plugins/modules/ipaclient_*
rm plugins/action_plugins/ipaclient_* rm plugins/action_plugins/ipaclient_*
git reset --hard git reset --hard
...@@ -2,11 +2,14 @@ import sys ...@@ -2,11 +2,14 @@ import sys
import re import re
def galaxify_playbook(playbook_in): def galaxify_playbook(playbook_in, project_prefix, collection_prefix):
p1 = re.compile('(ipa.*:)$') p1 = re.compile('(%s.*:)$' % project_prefix)
p2 = re.compile('(.*:) (ipa.*)$') p2 = re.compile('(.*:) (%s.*)$' % project_prefix)
lines = [] lines = []
pattern1 = r'%s.\1' % collection_prefix
pattern2 = r'\1 %s.\2' % collection_prefix
with open(playbook_in) as in_f: with open(playbook_in) as in_f:
changed = False changed = False
changeable = False changeable = False
...@@ -22,14 +25,13 @@ def galaxify_playbook(playbook_in): ...@@ -22,14 +25,13 @@ def galaxify_playbook(playbook_in):
elif stripped.startswith("include_role:"): elif stripped.startswith("include_role:"):
include_role = True include_role = True
elif include_role and stripped.startswith("name:"): elif include_role and stripped.startswith("name:"):
line = p2.sub(r'\1 freeipa.ansible_freeipa.\2', line) line = p2.sub(pattern2, line)
changed = True changed = True
elif changeable and stripped.startswith("- role:"): elif changeable and stripped.startswith("- role:"):
line = p2.sub(r'\1 freeipa.ansible_freeipa.\2', line) line = p2.sub(pattern2, line)
changed = True changed = True
elif changeable and not stripped.startswith( elif changeable and not stripped.startswith(collection_prefix):
"freeipa.ansible_freeipa."): line = p1.sub(pattern1, line)
line = p1.sub(r'freeipa.ansible_freeipa.\1', line)
changed = True changed = True
lines.append(line) lines.append(line)
...@@ -40,4 +42,4 @@ def galaxify_playbook(playbook_in): ...@@ -40,4 +42,4 @@ def galaxify_playbook(playbook_in):
out_f.write(line) out_f.write(line)
galaxify_playbook(sys.argv[1]) galaxify_playbook(sys.argv[1], sys.argv[2], sys.argv[3])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment