13 Commits
v0.23 ... v0.24

Author SHA1 Message Date
kewl
9f52f507c6 Merge pull request #25 from hvariant/fix-package-name-quote
fix quoting of package name
2019-08-31 09:02:49 +01:00
Zhansong Li
e1443632a3 use the correct module and function name 2019-08-31 17:41:39 +10:00
Zhansong Li
f4868a5bac fix quoting of package name 2019-08-31 11:17:57 +10:00
kewl fft
9a2500338c improved readme 2019-07-28 09:30:00 +02:00
kewl fft
5acabdc819 optional argument default for get bin path removed 2019-04-11 20:09:27 +01:00
kewl fft
2766c2661c if in one line 2019-04-11 20:03:55 +01:00
kewl fft
473d06fe54 revert grammatical correction 2019-04-11 19:59:22 +01:00
kewl fft
59d69056a2 grammatical correction always many packages at this point 2019-04-11 19:45:03 +01:00
kewl fft
8b1ba99cdc choices list is now dynamic 2019-04-11 19:39:01 +01:00
kewl fft
72d432ac7a yaourt remove from choices 2019-04-11 19:17:36 +01:00
kewl fft
b462d9893f improved error message when pkg not found thanks @juergenhoetzel 2019-04-11 19:05:57 +01:00
kewl fft
8f8af5fa5f correct package name in readme 2018-12-21 08:33:16 +00:00
kewl fft
6ee60c77bb yay afterclean added 2018-11-15 20:08:23 +00:00
2 changed files with 17 additions and 19 deletions

View File

@@ -1,14 +1,14 @@
# Ansible AUR helper
Ansible module to use some Arch User Repository (AUR) helpers as well as makepkg.
The following helpers are supported and automatically selected in the order they are listed:
The following helpers are supported and automatically selected, if present, in the order listed below:
- [yay](https://github.com/Jguer/yay)
- [aurman](https://github.com/polygamma/aurman)
- [pacaur](https://github.com/rmarquis/pacaur)
- [trizen](https://github.com/trizen/trizen)
- [pikaur](https://github.com/actionless/pikaur)
*makepkg* will be used if no helper was found or if it is explicitly specified.
*makepkg* will be used if no helper was found or if it is explicitly specified:
- [makepkg](https://wiki.archlinux.org/index.php/makepkg)
## Options
@@ -28,7 +28,7 @@ The following helpers are supported and automatically selected in the order they
## Installing
### AUR package
The [aur-ansible-git](https://aur.archlinux.org/packages/ansible-aur-git) package is available in the AUR.
The [ansible-aur-git](https://aur.archlinux.org/packages/ansible-aur-git) package is available in the AUR.
Note the module is installed in `/usr/share/ansible/plugins/modules` which is one of the default module library paths.
### Manual installation
@@ -38,9 +38,9 @@ git clone https://github.com/kewlfft/ansible-aur.git ~/.ansible/plugins/modules/
```
## Usage
### Note
* This module aims to cover the AUR; for package removal or system upgrade with the repositories, it is recommended to use the official *pacman* module,
* A package is reinstalled only if an update is available, using the *--needed* parameter.
### Notes
* This module aims to cover the AUR; for package removal or system upgrade with the repositories, it is recommended to use the official *pacman* module.
* The *--needed* parameter of the helper is systematically used, it means if a package is up to date, it is not built and reinstalled.
### Examples
Use it in a task, as in the following examples:
@@ -68,7 +68,7 @@ Use it in a task, as in the following examples:
```
### Create the "aur_builder" user
While Ansible expects to SSH as root, AUR helpers do not allow executing operations as root, they all fail with "you cannot perform this operation as root". It is therefore recommended to create a user, that we will call for example *aur_builder*, that has no need for password with pacman in sudoers.
While Ansible expects to SSH as root, AUR helpers do not allow executing operations as root, they all fail with "you cannot perform this operation as root". It is therefore recommended to create a user, let's call it *aur_builder*, that has no need for password with pacman in sudoers.
This can be done in Ansible with the following actions:
```
- user:

22
aur.py
View File

@@ -9,6 +9,7 @@ import tarfile
import os
import os.path
import tempfile
import urllib.parse
DOCUMENTATION = '''
@@ -76,7 +77,7 @@ EXAMPLES = '''
def_lang = ['env', 'LC_ALL=C']
use_cmd = {
'yay': ['yay', '-S', '--noconfirm', '--needed'],
'yay': ['yay', '-S', '--noconfirm', '--needed', '--cleanafter'],
'aurman': ['aurman', '-S', '--noconfirm', '--noedit', '--needed', '--skip_news', '--pgp_fetch', '--skip_new_locations'],
'pacaur': ['pacaur', '-S', '--noconfirm', '--noedit', '--needed'],
'trizen': ['trizen', '-S', '--noconfirm', '--noedit', '--needed'],
@@ -108,13 +109,13 @@ def check_packages(module, packages):
if would_be_changed:
status = True
if (len(packages) > 1):
message = '%s package(s) would be installed' % str(len(would_be_changed))
if len(packages) > 1:
message = '{} package(s) would be installed'.format(len(would_be_changed))
else:
message = 'package would be installed'
else:
status = False
if (len(packages) > 1):
if len(packages) > 1:
message = 'all packages are already installed'
else:
message = 'package is already installed'
@@ -126,10 +127,10 @@ def install_with_makepkg(module, package):
Install the specified package with makepkg
"""
module.get_bin_path('fakeroot', required=True)
f = open_url('https://aur.archlinux.org/rpc/?v=5&type=info&arg={}'.format(package))
f = open_url('https://aur.archlinux.org/rpc/?v=5&type=info&arg={}'.format(urllib.parse.quote(package)))
result = json.loads(f.read().decode('utf8'))
if result['resultcount'] != 1:
return (1, '', 'package not found')
return (1, '', 'package {} not found'.format(package))
result = result['results'][0]
f = open_url('https://aur.archlinux.org/{}'.format(result['URLPath']))
current_path = os.getcwd()
@@ -184,10 +185,7 @@ def install_packages(module, packages, use, skip_installed, aur_only):
changed_iter = changed_iter or not (out == '' or '-- skipping' in out or 'nothing to do' in out)
if changed_iter:
message = 'installed package(s)'
else:
message = 'package(s) already installed'
message = 'installed package(s)' if changed_iter else 'package(s) already installed'
module.exit_json(
changed=changed_iter,
@@ -209,7 +207,7 @@ def main():
},
'use': {
'default': 'auto',
'choices': ['auto', 'aurman', 'pacaur', 'trizen', 'pikaur', 'yaourt', 'yay', 'makepkg'],
'choices': ['auto'] + list(use_cmd.keys()),
},
'skip_installed': {
'default': False,
@@ -237,7 +235,7 @@ def main():
use = 'makepkg'
# auto: select the first helper for which the bin is found
for k in use_cmd:
if module.get_bin_path(k, False):
if module.get_bin_path(k):
use = k
break
else: