Skip to content

Instantly share code, notes, and snippets.

@konstruktoid
Created January 6, 2022 10:43
Show Gist options
  • Save konstruktoid/bad00e5948a02d3e8ff4a0ff8713be25 to your computer and use it in GitHub Desktop.
Save konstruktoid/bad00e5948a02d3e8ff4a0ff8713be25 to your computer and use it in GitHub Desktop.
crude Ansible FQCN converter
#!/bin/bash
set -uo pipefail
builtin="add_host
apt
apt_key
apt_repository
assemble
assert
async_status
blockinfile
command
copy
cron
debconf
debug
dnf
dpkg_selections
expect
fail
fetch
file
find
gather_facts
get_url
getent
git
group
group_by
hostname
import_playbook
import_role
import_tasks
include
include_role
include_tasks
include_vars
iptables
known_hosts
lineinfile
meta
package
package_facts
pause
ping
pip
raw
reboot
replace
rpm_key
script
service
service_facts
set_fact
set_stats
setup
shell
slurp
stat
subversion
systemd
sysvinit
tempfile
template
unarchive
uri
user
wait_for
wait_for_connection
yum
yum_repository"
community="docker"
community_general="modprobe
ufw"
posix="sysctl"
convert_to_fqcn () {
for directory in handlers molecule roles tasks; do
if [ -d "${directory}" ]; then
grep -rl "$1" "${directory}/"* | grep -v '.*\.bak$' | while read -r file; do
sed -i.bak "s/ ${action}:/ $2.${action}:/g" "${file}"
sed -i.bak "s/ ansible.builtin.group: root/ group: root/g" "${file}"
sed -i.bak "s/ ansible.builtin.replace: / replace: /g" "${file}"
done
fi
done
}
for action in ${builtin}; do
convert_to_fqcn "${action}" "ansible.builtin"
done
for action in ${community}; do
convert_to_fqcn "${action}" "community"
done
for action in ${community_general}; do
convert_to_fqcn "${action}" "community.general"
done
for action in ${posix}; do
convert_to_fqcn "${action}" "ansible.posix"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment