Created
June 11, 2013 18:03
-
-
Save jlaska/5759226 to your computer and use it in GitHub Desktop.
ansible/site_facts Make yum repository configuration available to ansible playbooks using the following site_facts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import os | |
import yum | |
def main(): | |
module = AnsibleModule( | |
argument_spec = dict( | |
yum_conf=dict(required=False, | |
default='/etc/yum.conf'), | |
) | |
) | |
yum_conf = module.params['yum_conf'] | |
yb = yum.YumBase() | |
if not yb.setCacheDir(force=True, reuse=False): | |
module.fail_json(msg="Can't create a tmp. cachedir.") | |
repo_dict = dict() | |
for id, repo in yb.repos.repos.items(): | |
repo_dict[id] = dict() | |
for attr in ['name', 'id', 'baseurl', 'gpgcheck', 'gpgfile', 'enabled', 'repofile']: | |
if hasattr(repo, attr): | |
repo_dict[id][attr] = getattr(repo, attr) | |
results = dict(ansible_facts=dict(yum_repos=repo_dict)) | |
module.exit_json(**results) | |
# include magic from lib/ansible/module_common.py | |
#<<INCLUDE_ANSIBLE_MODULE_COMMON>> | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment