Skip to content
This repository was archived by the owner on Jul 23, 2020. It is now read-only.

Commit 4b2d03f

Browse files
committed
Add the yum_plugins fact returning module
1 parent e4f2d12 commit 4b2d03f

File tree

2 files changed

+127
-4
lines changed

2 files changed

+127
-4
lines changed

README.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
ansible-plugins
2-
===============
3-
41
Ansible Plugins
2+
===============
53

6-
## Notification Plugins ##
4+
## Fact Modules ##
75

86
### cloudformation_stack_facts ###
97

@@ -70,6 +68,42 @@ The structure returned looks like this:
7068
"zone_type": "public"
7169
}
7270

71+
### yum_plugins ###
72+
73+
Basic module that returns facts for the yum plugins installed on the host.
74+
75+
- name: Retrieve yum plugin details
76+
yum_plugins:
77+
78+
- debug: var=yum_plugins
79+
80+
Sample output
81+
82+
TASK: [debug var=yum_plugins]
83+
*************************************************
84+
ok: [localhost] => {
85+
"var": {
86+
"yum_plugins": {
87+
"disabled": [
88+
"blacklist",
89+
"whiteout"
90+
],
91+
"enabled": [
92+
"langpacks",
93+
"refresh-packagekit"
94+
],
95+
"plugin": [
96+
"blacklist",
97+
"langpacks",
98+
"refresh-packagekit",
99+
"whiteout"
100+
]
101+
}
102+
}
103+
}
104+
105+
106+
## Modules ##
73107

74108
### changelog ###
75109

library/yum_plugins.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
# (c) 2015, Dean Wilson <dean.wilson@gmail.com>
5+
#
6+
# Ansible is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Ansible is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18+
19+
20+
import glob
21+
import re
22+
import os
23+
24+
DOCUMENTATION = '''
25+
---
26+
module: yum_plugins
27+
short_description: Retrieve yum plugin details
28+
description:
29+
- Retrieve yum plugin details
30+
author: Dean Wilson
31+
options:
32+
config_dir:
33+
description:
34+
- The plugin config directory. Defaults to /etc/yum/pluginconf.d
35+
required: false
36+
default: '/etc/yum/pluginconf.d'
37+
aliases: []
38+
'''
39+
40+
EXAMPLES = '''
41+
- name: Retrieve yum plugin details
42+
yum_plugins:
43+
44+
- debug: var=yum_plugins
45+
'''
46+
47+
48+
def main():
49+
module = AnsibleModule(
50+
argument_spec=dict(
51+
config_dir=dict(default='/etc/yum/pluginconf.d', required=False)
52+
)
53+
)
54+
55+
config_dir = module.params['config_dir']
56+
regexp = re.compile(r'enabled\s*=\s*1')
57+
58+
plugins = {
59+
'plugin': [],
60+
'enabled': [],
61+
'disabled': []
62+
}
63+
64+
files = glob.glob(config_dir + '/*.conf')
65+
66+
for file in files:
67+
filename = os.path.splitext(os.path.basename(file))[0]
68+
69+
plugins['plugin'].append(filename)
70+
71+
with open(file, 'r') as f:
72+
content = f.read()
73+
if regexp.search(content) is not None:
74+
plugins['enabled'].append(filename)
75+
else:
76+
plugins['disabled'].append(filename)
77+
78+
# sort the values
79+
for key in plugins:
80+
plugins[key].sort()
81+
82+
results = {
83+
'yum_plugins': plugins
84+
}
85+
86+
module.exit_json(ansible_facts=results)
87+
88+
from ansible.module_utils.basic import *
89+
main()

0 commit comments

Comments
 (0)