mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
urpmi: PEP8 compliancy and documentation changes (#33560)
This PR includes: - PEP8 compliancy changes - Documentation changes
This commit is contained in:
parent
95044d69c7
commit
aec8e7784a
2 changed files with 42 additions and 47 deletions
|
@ -1,21 +1,19 @@
|
||||||
#!/usr/bin/python -tt
|
#!/usr/bin/python -tt
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2013, Philippe Makowski
|
# Copyright: (c) 2013, Philippe Makowski
|
||||||
# Written by Philippe Makowski <philippem@mageia.org>
|
# Written by Philippe Makowski <philippem@mageia.org>
|
||||||
# Based on apt module written by Matthew Williams <matthew@flowroute.com>
|
# Based on apt module written by Matthew Williams <matthew@flowroute.com>
|
||||||
#
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# 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
|
from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: urpmi
|
module: urpmi
|
||||||
|
@ -26,77 +24,73 @@ version_added: "1.3.4"
|
||||||
options:
|
options:
|
||||||
pkg:
|
pkg:
|
||||||
description:
|
description:
|
||||||
- name of package to install, upgrade or remove.
|
- Name of package to install, upgrade or remove.
|
||||||
required: true
|
required: yes
|
||||||
default: null
|
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Indicates the desired package state
|
- Indicates the desired package state.
|
||||||
required: false
|
choices: [ absent, present ]
|
||||||
default: present
|
default: present
|
||||||
choices: [ "absent", "present" ]
|
|
||||||
update_cache:
|
update_cache:
|
||||||
description:
|
description:
|
||||||
- update the package database first C(urpmi.update -a).
|
- Update the package database first C(urpmi.update -a).
|
||||||
required: false
|
type: bool
|
||||||
default: no
|
default: 'no'
|
||||||
choices: [ "yes", "no" ]
|
|
||||||
no-recommends:
|
no-recommends:
|
||||||
description:
|
description:
|
||||||
- Corresponds to the C(--no-recommends) option for I(urpmi).
|
- Corresponds to the C(--no-recommends) option for I(urpmi).
|
||||||
required: false
|
type: bool
|
||||||
default: yes
|
default: 'yes'
|
||||||
choices: [ "yes", "no" ]
|
|
||||||
force:
|
force:
|
||||||
description:
|
description:
|
||||||
- Assume "yes" is the answer to any question urpmi has to ask.
|
- Assume "yes" is the answer to any question urpmi has to ask.
|
||||||
Corresponds to the C(--force) option for I(urpmi).
|
Corresponds to the C(--force) option for I(urpmi).
|
||||||
required: false
|
type: bool
|
||||||
default: yes
|
default: 'yes'
|
||||||
choices: [ "yes", "no" ]
|
|
||||||
root:
|
root:
|
||||||
description:
|
description:
|
||||||
- Specifies an alternative install root, relative to which all packages will be installed.
|
- Specifies an alternative install root, relative to which all packages will be installed.
|
||||||
Corresponds to the C(--root) option for I(urpmi).
|
Corresponds to the C(--root) option for I(urpmi).
|
||||||
required: false
|
default: /
|
||||||
default: "/"
|
|
||||||
version_added: "2.4"
|
version_added: "2.4"
|
||||||
aliases: [ "installroot" ]
|
aliases: [ installroot ]
|
||||||
author: "Philippe Makowski (@pmakowski)"
|
author:
|
||||||
notes: []
|
- Philippe Makowski (@pmakowski)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# install package foo
|
- name: Install package foo
|
||||||
- urpmi:
|
urpmi:
|
||||||
pkg: foo
|
pkg: foo
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
# remove package foo
|
- name: Remove package foo
|
||||||
- urpmi:
|
urpmi:
|
||||||
pkg: foo
|
pkg: foo
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
# description: remove packages foo and bar
|
- name: Remove packages foo and bar
|
||||||
- urpmi:
|
urpmi:
|
||||||
pkg: foo,bar
|
pkg: foo,bar
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
# description: update the package database (urpmi.update -a -q) and install bar (bar will be the updated if a newer version exists)
|
- name: Update the package database (urpmi.update -a -q) and install bar (bar will be the updated if a newer version exists)
|
||||||
- urpmi:
|
- urpmi:
|
||||||
name: bar
|
name: bar
|
||||||
state: present
|
state: present
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
import shlex
|
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
URPMI_PATH = '/usr/sbin/urpmi'
|
URPMI_PATH = '/usr/sbin/urpmi'
|
||||||
URPME_PATH = '/usr/sbin/urpme'
|
URPME_PATH = '/usr/sbin/urpme'
|
||||||
|
|
||||||
|
|
||||||
def query_package(module, name, root):
|
def query_package(module, name, root):
|
||||||
# rpm -q returns 0 if the package is installed,
|
# rpm -q returns 0 if the package is installed,
|
||||||
# 1 if it is not installed
|
# 1 if it is not installed
|
||||||
|
@ -107,6 +101,7 @@ def query_package(module, name, root):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def query_package_provides(module, name, root):
|
def query_package_provides(module, name, root):
|
||||||
# rpm -q returns 0 if the package is installed,
|
# rpm -q returns 0 if the package is installed,
|
||||||
# 1 if it is not installed
|
# 1 if it is not installed
|
||||||
|
@ -181,22 +176,25 @@ def install_packages(module, pkgspec, root, force=True, no_recommends=True):
|
||||||
else:
|
else:
|
||||||
module.exit_json(changed=False)
|
module.exit_json(changed=False)
|
||||||
|
|
||||||
|
|
||||||
def root_option(root):
|
def root_option(root):
|
||||||
if (root):
|
if (root):
|
||||||
return "--root=%s" % (root)
|
return "--root=%s" % (root)
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
state = dict(default='installed', choices=['installed', 'removed', 'absent', 'present']),
|
state=dict(type='str', default='installed', choices=['absent', 'installed', 'present', 'removed']),
|
||||||
update_cache = dict(default=False, aliases=['update-cache'], type='bool'),
|
update_cache=dict(type='bool', default=False, aliases=['update-cache']),
|
||||||
force = dict(default=True, type='bool'),
|
force=dict(type='bool', default=True),
|
||||||
no_recommends = dict(default=True, aliases=['no-recommends'], type='bool'),
|
no_recommends=dict(type='bool', default=True, aliases=['no-recommends']),
|
||||||
package = dict(aliases=['pkg', 'name'], required=True),
|
package=dict(type='str', required=True, aliases=['name', 'pkg']),
|
||||||
root = dict(aliases=['installroot'])))
|
root=dict(type='str', aliases=['installroot']),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
if not os.path.exists(URPMI_PATH):
|
if not os.path.exists(URPMI_PATH):
|
||||||
module.fail_json(msg="cannot find urpmi, looking for %s" % (URPMI_PATH))
|
module.fail_json(msg="cannot find urpmi, looking for %s" % (URPMI_PATH))
|
||||||
|
@ -212,14 +210,12 @@ def main():
|
||||||
|
|
||||||
packages = p['package'].split(',')
|
packages = p['package'].split(',')
|
||||||
|
|
||||||
if p['state'] in [ 'installed', 'present' ]:
|
if p['state'] in ['installed', 'present']:
|
||||||
install_packages(module, packages, root, force_yes, no_recommends_yes)
|
install_packages(module, packages, root, force_yes, no_recommends_yes)
|
||||||
|
|
||||||
elif p['state'] in [ 'removed', 'absent' ]:
|
elif p['state'] in ['removed', 'absent']:
|
||||||
remove_packages(module, packages, root)
|
remove_packages(module, packages, root)
|
||||||
|
|
||||||
# import module snippets
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -273,7 +273,6 @@ lib/ansible/modules/packaging/os/portinstall.py
|
||||||
lib/ansible/modules/packaging/os/sorcery.py
|
lib/ansible/modules/packaging/os/sorcery.py
|
||||||
lib/ansible/modules/packaging/os/svr4pkg.py
|
lib/ansible/modules/packaging/os/svr4pkg.py
|
||||||
lib/ansible/modules/packaging/os/swdepot.py
|
lib/ansible/modules/packaging/os/swdepot.py
|
||||||
lib/ansible/modules/packaging/os/urpmi.py
|
|
||||||
lib/ansible/modules/packaging/os/zypper.py
|
lib/ansible/modules/packaging/os/zypper.py
|
||||||
lib/ansible/modules/packaging/os/zypper_repository.py
|
lib/ansible/modules/packaging/os/zypper_repository.py
|
||||||
lib/ansible/modules/storage/infinidat/infini_export.py
|
lib/ansible/modules/storage/infinidat/infini_export.py
|
||||||
|
|
Loading…
Add table
Reference in a new issue