Some Ansible roles and playbooks to help me distro-hop 😜
This has been tested only manually and on Fedora 34. So feel free to use it, but at your own risk. Always review code you find online before running it.
-
Install Ansible and, optionally, Ansible Runner:
pip install ansible ansible-runner
-
Install needed Ansible collections:
ansible-galaxy collection install ansible.posix community.crypto community.general
-
Clone this repository. I will refer to the destination directory of the cloned repo as
${HOP_DIR}
. You can set this variable for your current shell so you can directly copy and paste the commands provided here:export HOP_DIR=<the actual directory here> # bash set -gx HOP_DIR <the actual directory here> # fish
-
Setup your playbook inside
${HOP_DIR}/project/
. The playbook I use isproject/fedora.yml
, so I will use it in the command examples. Replace it with your own if not editing it directly. The Roles and variables section below describes the available roles and its variables. -
Run with either
ansible-playbook
(it comes with Ansible) oransible-runner
. Preferansible-runner
when running the playbook multiple times, e.g. when experimenting, since it will automatically fill in yoursudo
password.-
With
ansible-playbook
:ansible-playbook -K ${HOP_DIR}/project/fedora.yml
-
With
ansible-runner
:-
Tell your
sudo
password. Fill it in${HOP_DIR}/env/passwords
(replacingyour sudo password
; you can undo the changes when done). -
Run:
ansible-runner run -p fedora.yml ${HOP_DIR}
-
-
Roles are what provide the automation of tasks.
The majority of them have variables which allow the customization of what they do.
They are specified in two files inside every role directory (project/roles/<role>/
):
defaults/main.yml
(this is the main one)vars/main.yml
Below is a list of the available roles and their important variables.
Refer to project/fedora.yml
for usage examples.
conda
Install miniconda using the official Linux installer.
Variables:
install_dir
: installation directory. Defaults to~/miniconda3/
debian
Install packages using apt
.
Variables:
cleanup
: whether to runautoclean
andautoremove
at the end. Defaults toyes
system_packages
: list of packages to install. Defaults to[]
(nothing)update_all
: whether to upgrade every installed package as first step. Defaults toyes
elementary os
Just delegates to the debian
role.
Refer to its description.
files
Download remote files or create links to local files.
Variables:
download
: list of mappings describing files that should be downloaded. The available keys areurl
anddest
. Defaults to[]
(nothing)link
: list of mappings describing links that should be created. The available keys aresrc
anddest
. Defaults to[]
(nothing)
In any case, the role will perform a backup of dest
before replacing it.
The backup will be placed at <dest>.backup-<datetime>
,
where <datetime>
is a simplified version of the current date and time in ISO 8601 format.
Note that the backup will end up beside dest
if it's a file or inside it if it's a directory.
Also, backups of already backed up directories will contain the older backups.
flatpak
Configure Flatpak and install packages.
Variables:
add_flathub
: whether to add Flathub repository. Defaults toyes
packages
: list of packages to install. Defaults to[]
(nothing)
fonts
Shortcut to install some fonts I like (Fira Code, Google's Noto, and JetBrains Mono).
Variables:
fonts_target_dir
: fonts installation directory. Defaults to~/.local/share/fonts/
jetbrains_mono_version
: version of the JetBrains Mono font to install. Defaults to2.225
. Choose a tag from the releases page
google-cloud-sdk
Install Google Cloud SDK using the official Linux installer.
It's also possible to install it via the snap
role.
Variables:
cloudsdk_install_dir
: installation base directory. Defaults to~/
(installer will create a dedicated directory in here)
install
Generic role to install system packages that share the name in Debian-based and RedHat-based distros.
Variables:
system
: list of packages to install. Defaults to[]
(nothing)
redhat
Install packages using dnf
.
Variables:
cleanup
: whether to run andautoremove
at the end. Defaults toyes
system_packages
: list of packages to install. Defaults to[]
(nothing)update_all
: whether to upgrade every installed package as first step. Defaults toyes
rust
Install Rust using the official Linux installer.
Has no variables.
Currently, accepts the default settings from the install script and does not modify PATH
.
snap
Configure Snap and install packages.
Variables:
channel
: channel to use to install the packages. Defaults tostable
classic_packages
: list of packages requiring classic confinement to install. Defaults to[]
(nothing)packages
: list of packages to install. Defaults to[]
(nothing)
sysctl
Configure sysctl
entries.
Variables:
sysctl_entries
: mapping of entries and its values to set. Defaults to{}
(nothing)sysctl_reload
: whether to reloadsysctl
after each entry. Defaults toyes
user
General user-related settings.
Variables:
git_user_email
: email to globally set to git'suser.email
. Has no defaults and skips it if not providedgit_user_name
: name to globally set to git'suser.name
. Has no defaults and skips it if not providedssh_keys
: list of names of SSH keys to create, relative tossh_keys_dir
. Defaults to[]
(nothing)ssh_keys_comment
: comment to add to every created key. Defaults to the value of thegit_user_email
variable or no comment if that's not providedssh_keys_dir
: directory in which to create the keys. Defaults to~/.ssh
ssh_keys_type
: type of keys to create. Defaults toed25519
user_login_shell
: name of login shell to set for current user (separately installed). Defaults tobash