support name type list

pull/1/head
alex 2017-12-23 21:05:07 +01:00
parent 0c083b7899
commit 091077c382
2 changed files with 32 additions and 28 deletions

View File

@ -13,7 +13,7 @@
## Options
|parameter|required |default |choices |comments|
|--- |--- |--- |--- |---|
|name |no | | |Name of the package to install or upgrade.|
|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.|
@ -21,28 +21,32 @@
## Usage
1. Add as a submodule in your playbook:
```
mkdir -p library/external_modules
git submodule add git://github.com/kewlfft/ansible-aur.git library/external_modules/ansible-aur
```
```
mkdir -p library/external_modules
git submodule add git://github.com/kewlfft/ansible-aur.git library/external_modules/ansible-aur
```
2. Link the binary to the base of `library/`:
```
ln -s external_modules/ansible-aur/aur library/aur
```
```
ln -s external_modules/ansible-aur/aur library/aur
```
3. Use it in a task, as in the following examples:
```
# Install (using pacaur)
- aur: name=package_name
become: yes
become_user: user_that_has_nopasswd_in_sudoers_for_pacman_use
```
# Install (using pacaur)
- aur: name=package_name
become: yes
become_user: user_that_has_nopasswd_in_sudoers_for_pacman_use
# Install (using trizen)
- aur: name=package_name helper=trizen
[...]
# Install (using trizen)
- aur:
helper: trizen
name:
- package_name_1
- package_name_2
[...]
# Upgrade (using pacaur)
- aur: upgrade=yes
[...]
```
# Upgrade (using pacaur)
- aur: upgrade=yes
[...]
```

16
aur.py
View File

@ -24,18 +24,18 @@ def upgrade(module, helper):
)
def install_packages(module, package_name, helper):
def install_packages(module, packages, helper):
assert helper in helper_cmd
cmd = helper_cmd[helper] + [package_name]
changed_iter = False
for package in packages:
cmd = helper_cmd[helper] + [package]
if upgrade:
cmd += ['-u']
rc, out, err = module.run_command(cmd, check_rc=True)
rc, out, err = module.run_command(cmd, check_rc=True)
changed_iter = changed_iter or not (out == '' or '-- skipping' in out)
module.exit_json(
changed=not (out == '' or '-- skipping' in out),
changed=changed_iter,
msg='installed package',
)
@ -44,7 +44,7 @@ def main():
module = AnsibleModule(
argument_spec={
'name': {
'required': False,
'type': 'list',
},
'upgrade': {
'default': False,