Installs the newest fish shell on Ubuntu via the fish PPA repository, allows fish as a login shell, and configures the fish shell according to my preferences for remote user. It also configures fish as the login shell for this user.
- user
-
The name of user for whom to configure fish.
To use this role, you’ll need to install Ansible and the role.
-
Install Ansible.
- Ubuntu
-
-
Install pip for python3.
➜ sudo apt -y install python3-pip
-
Install the Ansible package.
➜ python3 -m pip --user install ansible
-
Ensure that
~/.local/bin
is on your path.- fish
-
➜ fish_add_path -p ~/.local/bin
- Bash / ZSH
-
➜ export PATH=~/.local/bin:$PATH
-
- Fedora
-
➜ sudo dnf -y install ansible
-
Create a roles directory in the current folder to place the role.
➜ mkdir roles
-
Checkout the role’s repository from GitHub into the
roles
directory.➜ git clone https://github.com/jwillikers/ansible_fish.git roles/ansible_fish
-
Run the role. Here, the role is run against the local machine.
- Command-Line
-
➜ ansible localhost --connection=local --ask-become-pass -m include_role \ -a name=ansible_fish -e user=$USER
- Playbook
-
-
Create a playbook which includes the role.
my-playbook.yml--- - hosts: localhost roles: - role: ansible_fish
-
Execute the playbook.
➜ ansible-playbook my-playbook.yml -i "localhost," --connection=local \ --ask-become-pass
-
This project uses Molecule for testing. The sections below describe how to setup Molecule and run the tests.
This project uses Ansible, Python, Molecule, and Podman. asdf is used to manage the Python runtime along with direnv and Pipenv to manage the project’s virtual environment and Python dependencies. This promotes flexible, cross-distribution environments and makes builds more reproducible. Instructions for installing everything are provided below.
-
Install the dependencies needed for asdf.
➜ sudo apt -y install curl git
-
If you use Btrfs and want to exclude the
~/.asdf
directory from snapshots of your home directory, create a subvolume for it.➜ btrfs subvolume create ~/.asdf
-
Pull down the asdf repository in to your home directory.
➜ git clone https://github.com/asdf-vm/asdf.git ~/.asdf
-
Checkout the latest version of asdf.
- fish
-
➜ git -C ~/.asdf switch --detach (git -C ~/.asdf describe --abbrev=0 --tags) HEAD is now at c6145d0 Update version to 0.8.0
- Bash / ZSH
-
➜ git -C ~/.asdf switch --detach $(git -C ~/.asdf describe --abbrev=0 --tags) HEAD is now at c6145d0 Update version to 0.8.0
-
Enable asdf in your shell.
- fish
-
➜ mkdir -p ~/.config/fish/conf.d; \ and echo "source ~/.asdf/asdf.fish" > ~/.config/fish/conf.d/asdf.fish
- Bash
-
➜ echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
- ZSH
-
➜ echo '. $HOME/.asdf/asdf.sh' >> ~/.zshrc
-
Install shell completions for asdf.
- fish
-
➜ mkdir -p ~/.config/fish/completions; \ and ln -s ~/.asdf/completions/asdf.fish ~/.config/fish/completions
- Bash
-
➜ echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
- ZSH
-
➜ echo -e 'fpath=(${ASDF_DIR}/completions $fpath)\nautoload -Uz compinit\ncompinit' >> ~/.zshrc
-
To make asdf available, reload your shell.
- fish
-
➜ exec fish
- Bash
-
➜ source ~/.bashrc
- ZSH
-
➜ source ~/.zshrc
-
Install the necessary dependencies to build Python which are helpfully documented in the Pyenv Wiki.
➜ sudo apt -y install make build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils \ tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
-
Add the Python plugin to asdf.
➜ asdf plugin add python
-
Before installing Pipenv, configure the default global Python version for the user.
You can use the system version of Python by default or another version of your choice.
❗Whenever the user’s global version of Python is updated, Pipenv must be reinstalled which may require that all virtual environments be rebuilt.
-
Use the system’s Python as the default.
-
Ubuntu installs Python as either
python2
orpython3
on the system.This means that asdf won’t be able to detect the system version of python. Install the Python package
python-is-python3
to install apython
executable for the system which usespython3
.➜ sudo apt -y install python-is-python3
-
Install pip and venv because they are not installed by default on Ubuntu.
➜ sudo apt -y install python3-pip python3-venv
-
Set the user’s Python to the system-wide version.
➜ asdf global python system
-
-
Or, you can use another version of Python for your user such as the latest and greatest version.
-
Build and install the latest version of Python.
➜ asdf install python latest
-
Set the user’s Python to the latest version available at this time.
- fish
-
➜ asdf global python (asdf latest python)
- Bash / ZSH
-
➜ asdf global python $(asdf latest python)
-
-
-
Install pipx for installing Pipenv in an isolated environment.
➜ python -m pip install --user pipx
-
Add the directory where pip installs executables for the local user to
PATH
.➜ python -m pipx ensurepath
-
To make executables installed by pipx available, reload your shell.
- fish
-
➜ exec fish
- Bash
-
➜ source ~/.bashrc
- ZSH
-
➜ source ~/.zshrc
-
Install Pipenv.
➜ python -m pipx install pipenv
-
Add the direnv plugin to asdf.
➜ asdf plugin add direnv
-
Integrate direnv with your shell.
- fish
-
➜ mkdir -p ~/.config/fish/conf.d; \ and echo "asdf exec direnv hook fish | source" > ~/.config/fish/conf.d/direnv.fish
- Bash
-
➜ echo 'eval "$(asdf exec direnv hook bash)"' >> ~/.bashrc
- ZSH
-
➜ echo 'eval "$(asdf exec direnv hook zsh)"' >> ~/.zshrc
-
Make the asdf feature, i.e. the command
use asdf
, available in direnv.- fish
-
➜ mkdir -p ~/.config/direnv; \ and echo 'source "$(asdf direnv hook asdf)"' >> ~/.config/direnv/direnvrc
- Bash / ZSH
-
➜ mkdir -p ~/.config/direnv; echo 'source "$(asdf direnv hook asdf)"' >> ~/.config/direnv/direnvrc
ℹ️The direnvrc
file should only use Bash syntax. -
Add completions for Pipenv to your shell.
- fish
-
➜ echo "eval (pipenv --completion)" > ~/.config/fish/completions/pipenv.fish
- Bash
-
➜ echo 'eval "$(pipenv --completion)"' >> ~/.bashrc
- ZSH
-
➜ echo 'eval "$(pipenv --completion)"' >> ~/.zshrc
-
Clone this project’s Git repository.
➜ git clone https://github.com/jwillikers/ansible_fish.git ~/Projects/ansible_fish
-
Change to the project directory.
➜ cd ~/Projects/ansible_fish
-
Run asdf to automatically install Python and direnv.
➜ asdf install
💡If you haven’t set a default global version of direnv, you should do so now.
- fish
-
➜ asdf global direnv (asdf list direnv | awk 'FNR <= 1')
- Bash / ZSH
-
➜ asdf global direnv $(asdf list direnv | awk 'FNR <= 1')
-
Reload your shell for direnv to be available.
- fish
-
➜ exec fish direnv: error /home/ubuntu/Source/MyProject/.envrc is blocked. Run `direnv allow` to approve its content
- Bash
-
➜ source ~/.bashrc direnv: error /home/ubuntu/Source/MyProject/.envrc is blocked. Run `direnv allow` to approve its content
- ZSH
-
➜ source ~/.zshrc direnv: error /home/ubuntu/Source/MyProject/.envrc is blocked. Run `direnv allow` to approve its content
-
Enable automatic loading of the project’s environment.
➜ direnv allow
Now, whenever you change into the project directory, the project’s virtual environment will automatically be loaded for you.
Contributions in the form of issues, feedback, and even pull requests are welcome. Make sure to adhere to the project’s Code of Conduct.
The project’s Code of Conduct is available in the Code of Conduct file.
This repository is licensed under the GPLv3, available in the license file.
© 2021 Jordan Williams