yum_repository: Add diff support (#3460)

This commit is contained in:
Jiri Tyr 2016-11-17 18:20:31 +00:00 committed by Matt Clay
parent 90e0dc2a89
commit 9453f6b97a

View file

@ -21,6 +21,7 @@
import ConfigParser import ConfigParser
import os import os
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.pycompat24 import get_exception
@ -273,8 +274,8 @@ options:
required: false required: false
default: null default: null
description: description:
- URL to the proxy server that yum should use. Set to C(_none_) to disable - URL to the proxy server that yum should use. Set to C(_none_) to
the global proxy setting. disable the global proxy setting.
proxy_password: proxy_password:
required: false required: false
default: null default: null
@ -719,7 +720,12 @@ def main():
yumrepo = YumRepo(module) yumrepo = YumRepo(module)
# Get repo status before change # Get repo status before change
yumrepo_before = yumrepo.dump() diff = {
'before_header': yumrepo.params['dest'],
'before': yumrepo.dump(),
'after_header': yumrepo.params['dest'],
'after': ''
}
# Perform action depending on the state # Perform action depending on the state
if state == 'present': if state == 'present':
@ -728,10 +734,10 @@ def main():
yumrepo.remove() yumrepo.remove()
# Get repo status after change # Get repo status after change
yumrepo_after = yumrepo.dump() diff['after'] = yumrepo.dump()
# Compare repo states # Compare repo states
changed = yumrepo_before != yumrepo_after changed = diff['before'] != diff['after']
# Save the file only if not in check mode and if there was a change # Save the file only if not in check mode and if there was a change
if not module.check_mode and changed: if not module.check_mode and changed:
@ -743,11 +749,7 @@ def main():
changed = module.set_fs_attributes_if_different(file_args, changed) changed = module.set_fs_attributes_if_different(file_args, changed)
# Print status of the change # Print status of the change
module.exit_json(changed=changed, repo=name, state=state) module.exit_json(changed=changed, repo=name, state=state, diff=diff)
# Import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':