2014-09-30 09:59:01 +00:00
|
|
|
#!/usr/bin/python
|
2015-10-07 15:52:52 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2017-08-02 16:17:54 +00:00
|
|
|
# Copyright: Ansible Project
|
2017-08-01 21:37:37 +00:00
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2014-09-30 09:59:01 +00:00
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-03-14 16:07:22 +00:00
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
2016-12-06 10:35:25 +00:00
|
|
|
|
2014-09-30 09:59:01 +00:00
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: dpkg_selections
|
|
|
|
short_description: Dpkg package selection selections
|
|
|
|
description:
|
|
|
|
- Change dpkg package selection state via --get-selections and --set-selections.
|
|
|
|
version_added: "2.0"
|
2018-08-24 23:43:35 +00:00
|
|
|
author:
|
2018-11-20 19:31:35 +00:00
|
|
|
- Brian Brazil (@brian-brazil) <brian.brazil@boxever.com>
|
2014-09-30 09:59:01 +00:00
|
|
|
options:
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- Name of the package
|
|
|
|
required: true
|
|
|
|
selection:
|
|
|
|
description:
|
|
|
|
- The selection state to set the package to.
|
|
|
|
choices: [ 'install', 'hold', 'deinstall', 'purge' ]
|
|
|
|
required: true
|
|
|
|
notes:
|
|
|
|
- This module won't cause any packages to be installed/removed/purged, use the C(apt) module for that.
|
|
|
|
'''
|
|
|
|
EXAMPLES = '''
|
|
|
|
# Prevent python from being upgraded.
|
2016-12-01 16:07:13 +00:00
|
|
|
- dpkg_selections:
|
|
|
|
name: python
|
|
|
|
selection: hold
|
2014-09-30 09:59:01 +00:00
|
|
|
'''
|
|
|
|
|
2018-02-02 00:30:08 +00:00
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
|
2017-12-07 16:27:06 +00:00
|
|
|
|
2014-09-30 09:59:01 +00:00
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
2017-05-01 15:25:39 +00:00
|
|
|
argument_spec=dict(
|
|
|
|
name=dict(required=True),
|
|
|
|
selection=dict(choices=['install', 'hold', 'deinstall', 'purge'])
|
2014-09-30 09:59:01 +00:00
|
|
|
),
|
|
|
|
supports_check_mode=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
dpkg = module.get_bin_path('dpkg', True)
|
|
|
|
|
|
|
|
name = module.params['name']
|
|
|
|
selection = module.params['selection']
|
|
|
|
|
|
|
|
# Get current settings.
|
|
|
|
rc, out, err = module.run_command([dpkg, '--get-selections', name], check_rc=True)
|
|
|
|
if not out:
|
|
|
|
current = 'not present'
|
|
|
|
else:
|
|
|
|
current = out.split()[1]
|
|
|
|
|
|
|
|
changed = current != selection
|
|
|
|
|
|
|
|
if module.check_mode or not changed:
|
2017-01-30 23:01:47 +00:00
|
|
|
module.exit_json(changed=changed, before=current, after=selection)
|
2014-09-30 09:59:01 +00:00
|
|
|
|
|
|
|
module.run_command([dpkg, '--set-selections'], data="%s %s" % (name, selection), check_rc=True)
|
|
|
|
module.exit_json(changed=changed, before=current, after=selection)
|
|
|
|
|
|
|
|
|
2016-12-05 16:23:08 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|