mirror of https://github.com/kewlfft/ansible-aur
auto helper mode added
parent
d0bddf7953
commit
843233987a
12
README.md
12
README.md
|
@ -6,11 +6,11 @@ Ansible module to use some AUR helpers. The following helpers are supported:
|
|||
- [yay](https://github.com/Jguer/yay)
|
||||
|
||||
## Options
|
||||
|parameter|required |default |choices |comments|
|
||||
|--- |--- |--- |--- |---|
|
||||
|name |no | | |Name or list of names of the package(s) to install or upgrade.|
|
||||
|upgrade |no |no |yes, no |Whether or not to upgrade whole system.|
|
||||
|helper |no |pacaur |pacaur, trizen, yaourt, yay |Helper to use.|
|
||||
|parameter|required |default |choices |comments|
|
||||
|--- |--- |--- |--- |---|
|
||||
|name |no | | |Name or list of names of the package(s) to install or upgrade.|
|
||||
|upgrade |no |no |yes, no |Whether or not to upgrade whole system.|
|
||||
|use |no |auto |auto, pacaur, trizen, yaourt, yay |The helper to use, 'auto' uses the first helper found in the list.|
|
||||
|
||||
### Note
|
||||
Either *name* or *upgrade* is required, both can not be used together.
|
||||
|
@ -43,7 +43,7 @@ Use it in a task, as in the following examples:
|
|||
|
||||
# Install (using trizen)
|
||||
- aur:
|
||||
helper: trizen
|
||||
use: trizen
|
||||
name:
|
||||
- package_name_1
|
||||
- package_name_2
|
||||
|
|
34
aur.py
34
aur.py
|
@ -4,32 +4,32 @@ from ansible.module_utils.basic import *
|
|||
|
||||
|
||||
helper_cmd = {
|
||||
'pacaur': ['env', 'LC_ALL=C', 'pacaur', '-S', '--noconfirm', '--noedit', '--needed', '--aur'],
|
||||
'trizen': ['env', 'LC_ALL=C', 'trizen', '-S', '--noconfirm', '--noedit', '--needed', '--aur'],
|
||||
'pacaur': ['env', 'LC_ALL=C', 'pacaur', '-S', '--noconfirm', '--noedit', '--needed', '--aur'],
|
||||
'yaourt': ['env', 'LC_ALL=C', 'yaourt', '-S', '--noconfirm', '--needed'],
|
||||
'yay': ['env', 'LC_ALL=C', 'yay', '-S', '--noconfirm'],
|
||||
}
|
||||
|
||||
|
||||
def upgrade(module, helper):
|
||||
assert helper in helper_cmd
|
||||
def upgrade(module, use):
|
||||
assert use in helper_cmd
|
||||
|
||||
cmd = helper_cmd[helper] + ['-u']
|
||||
cmd = helper_cmd[use] + ['-u']
|
||||
|
||||
rc, out, err = module.run_command(cmd, check_rc=True)
|
||||
|
||||
module.exit_json(
|
||||
changed=not (out == '' or 'there is nothing to do' in out or 'No AUR update found' in out),
|
||||
changed=not (out == '' or 'there is nothing to do' in out or 'No AUR updates found' in out),
|
||||
msg='upgraded system',
|
||||
)
|
||||
|
||||
|
||||
def install_packages(module, packages, helper):
|
||||
assert helper in helper_cmd
|
||||
def install_packages(module, packages, use):
|
||||
assert use in helper_cmd
|
||||
|
||||
changed_iter = False
|
||||
for package in packages:
|
||||
cmd = helper_cmd[helper] + [package]
|
||||
cmd = helper_cmd[use] + [package]
|
||||
|
||||
rc, out, err = module.run_command(cmd, check_rc=True)
|
||||
changed_iter = changed_iter or not (out == '' or '-- skipping' in out)
|
||||
|
@ -50,9 +50,9 @@ def main():
|
|||
'default': False,
|
||||
'type': 'bool',
|
||||
},
|
||||
'helper': {
|
||||
'default': 'pacaur',
|
||||
'choices': ['pacaur', 'trizen', 'yaourt', 'yay'],
|
||||
'use': {
|
||||
'default': 'auto',
|
||||
'choices': ['auto', 'pacaur', 'trizen', 'yaourt', 'yay'],
|
||||
},
|
||||
},
|
||||
required_one_of=[['name', 'upgrade']],
|
||||
|
@ -60,12 +60,20 @@ def main():
|
|||
|
||||
params = module.params
|
||||
|
||||
if params['use'] == 'auto':
|
||||
for k in helper_cmd:
|
||||
if module.get_bin_path(k, False):
|
||||
helper = k
|
||||
break
|
||||
else:
|
||||
helper = params['use']
|
||||
|
||||
if params['upgrade'] and params['name']:
|
||||
module.fail_json(msg="Upgrade and install must be requested separately")
|
||||
if params['upgrade']:
|
||||
upgrade(module, params['helper'])
|
||||
upgrade(module, helper)
|
||||
else:
|
||||
install_packages(module, params['name'], params['helper'])
|
||||
install_packages(module, params['name'], helper)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue