looking for feedback on what ansible roles are mostly used so I can concentrate on a list. I'm going through right now on the postgresql_server role and going to make some changes.
I would say the most used roles would be the base one.. but here is how I tried to itemize it.
git clone ansible # do as needed cd ansible/playbooks [smooge@batcave01 playbooks (master)]$ find . -type f -print | xargs grep -l roles: | xargs awk '/roles:/{flag=1;next}/:/{flag=0}flag; /role:/{print " - "$NF}' | awk '{for (i=1; i<=NF; i++){ if ($i~/-/ || $i~/role:/){print $(i+1)};} }' | sort | uniq -c | sort -bnr | head -n 25 136 } 124 108 httpd/website 105 base 99 nagios_client 96 rkhunter 95 hosts 94 fas_client 93 httpd/reverseproxy 87 sudo 80 collectd/base 74 httpd/redirect 54 openshift/object 42 openvpn/client, 42 httpd/redirectmatch 40 fedmsg/base 33 keytab/service 31 rsyncd 27 basessh 23 nfs/client 19 httpd/certificate 17 openshift/secret-file 17 collectd/fedmsg-service 14 fedmsg/hub 14 apache
The above may not be correct so please double check yourself and come up with a better pattern match.
Possibly a prettier, if more verbose, way to do this (though I truly envy @smooge's awk abilities)
awk
import os import yaml paths = [ '/srv/web/infra/ansible/playbooks/groups', '/srv/web/infra/ansible/playbooks/hosts' ] counts = {} files = [] for path in paths: d = os.listdir(path) for f in d: if f.endswith('.yml'): files.append(path + '/' + f) for f in files: with open(f, 'r') as stream: try: q = yaml.load(stream) things_with_roles = [x for x in q if 'roles' in x] for thing in things_with_roles: for role in thing['roles']: if isinstance(role, dict): if role['role'] in counts: counts[role['role']] += 1 else: counts[role['role']] = 1 else: if role in counts: counts[role] += 1 else: counts[role] = 1 except yaml.YAMLError as exc: print exc for k in reversed(sorted(counts, key=counts.get)): print "%s\t\t%s" % (k,counts[k])
gives
base 106 nagios_client 102 sudo 101 hosts 100 fas_client 99 rkhunter 98 collectd/base 88 openvpn/client 64 fedmsg/base 51 nfs/client 45 rsyncd 35 keytab/service 32 mod_wsgi 28 basessh 26 apache 22 collectd/fedmsg-service 18 fedmsg/hub 15 osbs-secret 9 postgresql_server 6 mariadb_server 5 push-docker 5 httpd/mod_ssl 5 cgit/make_pkgs_list 4 httpd/certificate 4 builder_repo 4
I'm going to close this since there is no actionable item here.
Metadata Update from @codeblock: - Issue close_status updated to: Invalid - Issue status updated to: Closed (was: Open)
Caveat: This doesn't actually take number of hosts into account, for the group playbooks. So there might be only one playbook that calls in the foo role, but that playbook might control 50 hosts. My script will only count that as one.
foo
In other words, this is a count of playbooks that use each role, not hosts that have that role applied.