ansible-aur/README.md

171 lines
8.5 KiB
Markdown
Raw Permalink Normal View History

# Ansible Collection - kewlfft.aur
## Description
This collection includes an Ansible module to manage packages from the AUR.
## Installation
### Install the `kewlfft.aur` collection from Ansible Galaxy
2021-09-03 20:30:57 +03:00
To install this collection from Ansible Galaxy, run the following command:
```shell
ansible-galaxy collection install kewlfft.aur
```
2021-09-03 20:30:57 +03:00
Alternatively, you can include the collection in a `requirements.yml` file and then run `ansible-galaxy collection install -r requirements.yml`. Here is an example of `requirements.yml` file:
```yaml
collections:
- name: kewlfft.aur
```
### Install the `kewlfft.aur` collection from the AUR
The `kewlfft.aur` collection is also available in the AUR as the [`ansible-collection-kewlfft-aur`](https://aur.archlinux.org/packages/ansible-collection-kewlfft-aur/) package.
### Install the `kewlfft.aur` collection locally for development
If you want to test changes to the source code, run the following commands from the root of this git repository to locally build and install the collection:
```shell
ansible-galaxy collection build --force
ansible-galaxy collection install --force "./kewlfft-aur-$(cat galaxy.yml | grep version: | awk '{print $2}').tar.gz"
```
### Install the `aur` module as a local custom module
Alternatively, you may manually install the `aur` module itself as a [local custom module](https://docs.ansible.com/ansible/latest/dev_guide/developing_locally.html) instead of installing the module through the `kewlfft.aur` Ansible collection. However, it is recommended to use `kewlfft.aur` collection unless you have a good reason not to. Here are the commands to install the `aur` module as a local custom module:
```shell
# Create the user custom module directory
mkdir ~/.ansible/plugins/modules
# Install the aur module into the user custom module directory
curl -o ~/.ansible/plugins/modules/aur.py https://raw.githubusercontent.com/kewlfft/ansible-aur/master/plugins/modules/aur.py
```
## kewlfft.aur.aur Module
Ansible module to use some Arch User Repository (AUR) helpers as well as makepkg.
2019-07-28 10:30:00 +03:00
The following helpers are supported and automatically selected, if present, in the order listed below:
2018-07-07 00:15:26 +03:00
- [yay](https://github.com/Jguer/yay)
2021-01-26 20:41:55 +03:00
- [paru](https://github.com/Morganamilo/paru)
2020-04-13 03:00:50 +03:00
- [pacaur](https://github.com/E5ten/pacaur)
2017-12-23 23:46:43 +03:00
- [trizen](https://github.com/trizen/trizen)
2018-03-17 11:15:06 +03:00
- [pikaur](https://github.com/actionless/pikaur)
2020-04-13 03:00:50 +03:00
- [aurman](https://github.com/polygamma/aurman) (discontinued)
2019-07-28 10:30:00 +03:00
*makepkg* will be used if no helper was found or if it is explicitly specified:
- [makepkg](https://wiki.archlinux.org/index.php/makepkg)
2017-12-23 20:27:42 +03:00
### Options
| Parameter | Choices/**Default** | Comments |
| -------------- | ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
| name | | Name or list of names of the package(s) to install or upgrade. |
| state | **present**, latest | Desired state of the package, 'present' skips operations if the package is already installed. |
| upgrade | yes, **no** | Whether or not to upgrade whole system. |
2021-10-22 12:23:07 +03:00
| update_cache | yes, **no** | Whether or not to refresh the packages cache |
| use | **auto**, yay, paru, pacaur, trizen, pikaur, aurman, makepkg | The tool to use, 'auto' uses the first known helper found and makepkg as a fallback. |
| extra_args | **null** | A list of additional arguments to pass directly to the tool. Cannot be used in 'auto' mode. |
| aur_only | yes, **no** | Limit helper operation to the AUR. |
| local_pkgbuild | Local directory with PKGBUILD, **null** | Only valid with makepkg or pikaur. Don't download the package from AUR. Build the package using a local PKGBUILD and the other build files. |
| skip_pgp_check | yes, **no** | Only valid with makepkg. Skip PGP signatures verification of source file, useful when installing packages without GnuPG properly configured. |
| ignore_arch | yes, **no** | Only valid with makepkg. Ignore a missing or incomplete arch field, useful when the PKGBUILD does not have the arch=('yourarch') field. |
2017-12-23 20:27:42 +03:00
#### Note
2017-12-31 20:15:35 +03:00
* Either *name* or *upgrade* is required, both cannot be used together.
* In the *use*=*auto* mode, makepkg is used as a fallback if no known helper is found.
2017-12-23 23:51:30 +03:00
### Usage
#### Notes
2020-05-24 16:54:40 +03:00
* The scope of this module is installation and update from the AUR; for package removal or for updates from 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.
#### Create the "aur_builder" user
2020-05-24 16:54:40 +03:00
While Ansible expects to SSH as root, makepkg or AUR helpers do not allow executing operations as root, they fail with "you cannot perform this operation as root". It is therefore recommended to create a user, which is non-root but has no need for password with pacman in sudoers, let's call it *aur_builder*.
2020-05-24 16:58:09 +03:00
This user can be created in an Ansible task with the following actions:
```yaml
- name: Create the `aur_builder` user
become: yes
ansible.builtin.user:
2020-05-24 16:54:40 +03:00
name: aur_builder
create_home: yes
2020-05-24 16:54:40 +03:00
group: wheel
- name: Allow the `aur_builder` user to run `sudo pacman` without a password
become: yes
ansible.builtin.lineinfile:
2020-05-24 16:54:40 +03:00
path: /etc/sudoers.d/11-install-aur_builder
line: 'aur_builder ALL=(ALL) NOPASSWD: /usr/bin/pacman'
create: yes
mode: 0644
2020-05-24 16:54:40 +03:00
validate: 'visudo -cf %s'
```
2017-12-23 23:54:19 +03:00
#### Fully Qualified Collection Names (FQCNs)
2021-09-03 20:29:20 +03:00
In order to use an Ansible module that is distributed in a collection, you must use its FQCN. This corresponds to "the full definition of a module, plugin, or role hosted within a collection, in the form `namespace.collection.content_name`" ([Source](https://github.com/ansible-collections/overview#terminology)). In this case, the `aur` module resides in the `aur` collection which is under the `kewlfft` namespace, so its FQCN is `kewlfft.aur.aur`.
Please note that this does not apply if you installed the `aur` module as a local custom module. Due to the nature of local custom modules, you can simply use the module's short name: `aur`.
#### Examples
2017-12-23 23:24:48 +03:00
Use it in a task, as in the following examples:
```yaml
2021-09-03 20:06:37 +03:00
# This task uses the module's short name instead of its FQCN (Fully Qualified Collection Name).
2021-09-03 20:08:21 +03:00
# Use the short name if the module was installed as a local custom module.
# Otherwise, if it was installed through the `kewlfft.aur` collection, this task will fail.
- name: Install trizen using makepkg if it isn't installed already
aur:
name: trizen
use: makepkg
state: present
2017-12-31 20:12:28 +03:00
become: yes
2017-12-31 23:05:06 +03:00
become_user: aur_builder
2017-12-31 20:12:28 +03:00
2021-09-03 20:06:37 +03:00
# This task uses the `aur` module's FQCN.
- name: Install trizen using makepkg if it isn't installed already
kewlfft.aur.aur:
name: trizen
use: makepkg
state: present
2020-05-24 16:54:40 +03:00
become: yes
become_user: aur_builder
2017-12-24 10:37:56 +03:00
- name: Install package_name_1 and package_name_2 using yay
kewlfft.aur.aur:
2020-05-24 16:54:40 +03:00
use: yay
2017-12-24 10:37:56 +03:00
name:
- package_name_1
2018-03-17 11:15:06 +03:00
- package_name_2
2017-12-31 23:05:06 +03:00
# Note: Dependency resolution will still include repository packages.
- name: Upgrade the system using yay, only act on AUR packages.
kewlfft.aur.aur:
upgrade: yes
use: yay
aur_only: yes
2020-09-24 13:31:55 +03:00
# Skip if it is already installed
- name: Install gnome-shell-extension-caffeine-git using pikaur and a local PKGBUILD.
kewlfft.aur.aur:
2020-09-24 13:31:55 +03:00
name: gnome-shell-extension-caffeine-git
use: pikaur
local_pkgbuild: {{ role_path }}/files/gnome-shell-extension-caffeine-git
state: present
become: yes
become_user: aur_builder
```