Skip to content

Commit

Permalink
fix(refactor): move tools and apt packages to install to the variables
Browse files Browse the repository at this point in the history
  • Loading branch information
IaroslavR committed May 4, 2023
1 parent 146cf41 commit 7a39705
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 79 deletions.
1 change: 0 additions & 1 deletion .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
warn_list:
- git-latest
- 'name[template]' # Jinja templates should only be at the end of ‘name’
- role-name[path]
exclude_paths:
Expand Down
71 changes: 68 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* [About](#about)
* [Usage](#usage)
* [Requirements](#requirements)
* [Role Variables](#role-variables)
* [Role Tags](#role-tags)
* [Usage Example](#usage-example)
* [Contributing](#contributing)

## About
Expand All @@ -22,8 +26,69 @@ This [Ansible][ans] role is designed to bootstrap a development server running U

```yaml
cache_valid_time: 3600
default_user_python_version: 3.10.11
asdf_expected: 0.11.3

apt_packages:
- apt-transport-https
- avahi-daemon
- avahi-utils
- byobu
- ca-certificates
- curl
- direnv
- git
- gnupg-agent
- htop
- iotop
- jq
- lsb-release
- make
- multitail
- podman
- python3
- python3-pip
- software-properties-common
- unzip
- wget
- whois

pyenv_version: 2.3.17

python_version: 3.10.11 # default Python for user

pipx_packages:
- awscli
- cookiecutter
- detect-secrets
- pre-commit
- yq

asdf_version: 0.11.3
asdf_plugins:
- name: github-cli
repo: https://github.com/bartlomiejdanek/asdf-github-cli.git
- name: lazydocker
repo: https://github.com/comdotlinux/asdf-lazydocker.git
- name: nodejs
repo: https://github.com/asdf-vm/asdf-nodejs.git
- name: packer
repo: https://github.com/asdf-community/asdf-hashicorp.git
- name: sops
repo: https://github.com/feniix/asdf-sops.git
- name: terraform
repo: https://github.com/asdf-community/asdf-hashicorp.git
- name: terraform-docs
repo: https://github.com/looztra/asdf-terraform-docs
- name: terragrunt
repo: https://github.com/ohmer/asdf-terragrunt
- name: tflint
repo: https://github.com/skyzyx/asdf-tflint
asdf_global:
- name: lazydocker
version: latest
- name: github-cli
version: latest
- name: sops
version: latest
```
### Role Tags
Expand All @@ -34,7 +99,7 @@ asdf_expected: 0.11.3
- **_pipx_** - Install `pipix` and globally available tools, configure `.bashrc`.
- **_poetry_** - Install/update `poetry`, configure `.bashrc`.
- **_psql_** - Configure official `PostgreSQL` repository as `apt` source, install `psql` client.
- **_python_** - Install/update `pyenv`, build Python `default_user_python_version`, and configure it as global for user.
- **_python_** - Install/update `pyenv`, build Python `python_version`, and configure it as global for user.
- **_vagrant_** - Install `virtualbox` and `vagrant`

### Usage Example
Expand Down
63 changes: 61 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,65 @@

cache_valid_time: 3600

default_user_python_version: 3.10.11
apt_packages:
- apt-transport-https
- avahi-daemon
- avahi-utils
- byobu
- ca-certificates
- curl
- direnv
- git
- gnupg-agent
- htop
- iotop
- jq
- lsb-release
- make
- multitail
- podman
- python3
- python3-pip
- software-properties-common
- unzip
- wget
- whois

asdf_expected: 0.11.3
pyenv_version: 2.3.17

python_version: 3.10.11 # default Python for user

pipx_packages:
- awscli
- cookiecutter
- detect-secrets
- pre-commit
- yq

asdf_version: 0.11.3
asdf_plugins:
- name: github-cli
repo: https://github.com/bartlomiejdanek/asdf-github-cli.git
- name: lazydocker
repo: https://github.com/comdotlinux/asdf-lazydocker.git
- name: nodejs
repo: https://github.com/asdf-vm/asdf-nodejs.git
- name: packer
repo: https://github.com/asdf-community/asdf-hashicorp.git
- name: sops
repo: https://github.com/feniix/asdf-sops.git
- name: terraform
repo: https://github.com/asdf-community/asdf-hashicorp.git
- name: terraform-docs
repo: https://github.com/looztra/asdf-terraform-docs
- name: terragrunt
repo: https://github.com/ohmer/asdf-terragrunt
- name: tflint
repo: https://github.com/skyzyx/asdf-tflint
asdf_global:
- name: lazydocker
version: latest
- name: github-cli
version: latest
- name: sops
version: latest
48 changes: 23 additions & 25 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,39 @@
enabled: true

- name: Install/modify default Python for user
changed_when: false
args:
executable: /bin/bash
ansible.builtin.shell: >
PYENV_ROOT="$HOME/.pyenv" &&
PATH="$PYENV_ROOT/bin:$PATH" &&
eval "$(pyenv init --path)" &&
eval "$(pyenv init -)" &&
pyenv install {{ default_user_python_version }} &&
pyenv global {{ default_user_python_version }}
changed_when: false
ansible.builtin.shell: |
PYENV_ROOT="$HOME/.pyenv"
PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
pyenv install {{ python_version }}
pyenv global {{ python_version }}
- name: Install pipx
changed_when: false
ansible.builtin.shell: >
set -o pipefail &&
PYENV_ROOT="$HOME/.pyenv" &&
PATH="$PYENV_ROOT/bin:$PATH" &&
eval "$(pyenv init --path)" &&
eval "$(pyenv init -)" &&
PYENV_VERSION={{ default_user_python_version }} python -m pip install --user pipx
args:
executable: /bin/bash
changed_when: false
ansible.builtin.shell: |
PYENV_ROOT="$HOME/.pyenv"
PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
PYENV_VERSION={{ python_version }} python -m pip install --user pipx
- name: Install poetry
changed_when: false
ansible.builtin.shell: >
set -o pipefail &&
PYENV_ROOT="$HOME/.pyenv" &&
PATH="$PYENV_ROOT/bin:$PATH" &&
eval "$(pyenv init --path)" &&
eval "$(pyenv init -)" &&
curl -sSL https://install.python-poetry.org |
PYENV_VERSION={{ default_user_python_version }} python
args:
executable: /bin/bash
changed_when: false
ansible.builtin.shell: |
set -o pipefail
PYENV_ROOT="$HOME/.pyenv"
PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
curl -sSL https://install.python-poetry.org | PYENV_VERSION={{ python_version }} python
- name: Configure poetry
changed_when: false
Expand Down
2 changes: 2 additions & 0 deletions tasks/apt-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
become: true
ansible.builtin.apt:
upgrade: dist
autoclean: true
autoremove: true

- name: Check if reboot is required
changed_when: reboot_required.stat.exists
Expand Down
23 changes: 2 additions & 21 deletions tasks/apt.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
- name: Install packages
become: true
with_items:
- apt-transport-https
- avahi-daemon
- avahi-utils
- byobu
- ca-certificates
- curl
- direnv
- git
- gnupg-agent
- htop
- iotop
- jq
- lsb-release
- make
- multitail
- python3
- python3-pip
- software-properties-common
- unzip
- wget
with_items: "{{ apt_packages }}"

ansible.builtin.apt:
cache_valid_time: "{{ cache_valid_time }}"
name: "{{ item }}"
Expand Down
22 changes: 7 additions & 15 deletions tasks/asdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
depth: 1
dest: "{{ ansible_env.HOME }}/.asdf"
repo: https://github.com/asdf-vm/asdf.git
version: v{{ asdf_expected }}
version: v{{ asdf_version }}

- name: Add asdf config to the .bashrc
ansible.builtin.blockinfile:
Expand All @@ -18,21 +18,13 @@
changed_when: '"already added" not in is_asdf_plugin_installed.stderr'
failed_when: false
register: is_asdf_plugin_installed
with_items:
- github-cli https://github.com/bartlomiejdanek/asdf-github-cli.git
- lazydocker https://github.com/comdotlinux/asdf-lazydocker.git
- nodejs https://github.com/asdf-vm/asdf-nodejs.git
- packer https://github.com/asdf-community/asdf-hashicorp.git
- sops https://github.com/feniix/asdf-sops.git
- terraform https://github.com/asdf-community/asdf-hashicorp.git
- terraform-docs https://github.com/looztra/asdf-terraform-docs
- terragrunt https://github.com/ohmer/asdf-terragrunt
- tflint https://github.com/skyzyx/asdf-tflint
ansible.builtin.command: "{{ ansible_env.HOME }}/.asdf/bin/asdf plugin-add {{ item }}"
with_items: "{{ asdf_plugins }}"
ansible.builtin.command: "{{ ansible_env.HOME }}/.asdf/bin/asdf plugin-add {{ item.name }} {{ item.repo }}"

- name: Install tools
changed_when: '"already installed" not in is_asdf_tool_installed.stdout'
register: is_asdf_tool_installed
with_items:
- lazydocker
ansible.builtin.command: "{{ ansible_env.HOME }}/.asdf/bin/asdf install {{ item }} latest && {{ ansible_env.HOME }}/.asdf/bin/asdf global {{ item }} latest"
with_items: "{{ asdf_global }}"
ansible.builtin.shell: |
{{ ansible_env.HOME }}/.asdf/bin/asdf install {{ item.name }} {{ item.version }}
{{ ansible_env.HOME }}/.asdf/bin/asdf global {{ item.name }} {{ item.version }}
2 changes: 2 additions & 0 deletions tasks/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
- docker-compose-plugin
ansible.builtin.apt:
name: "{{ item }}"
cache_valid_time: "{{ cache_valid_time }}"


- name: Create docker group
become: true
Expand Down
4 changes: 2 additions & 2 deletions tasks/hstr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
- name: Install hstr
become: true
ansible.builtin.apt:
name:
- hstr
name: hstr
cache_valid_time: "{{ cache_valid_time }}"

- name: Add hstr config to the .bashrc
ansible.builtin.blockinfile:
Expand Down
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
tags:
- docker

- name: Add postgres
- name: Add PostgreSQL
tags:
- psql
ansible.builtin.include_tasks:
Expand Down
7 changes: 1 addition & 6 deletions tasks/pipx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,5 @@
- name: Install tools
changed_when: '"already seems to be installed" not in is_pipx_tool_installed.stdout'
register: is_pipx_tool_installed
with_items:
- awscli
- cookiecutter
- detect-secrets
- pre-commit
- yq
with_items: "{{ pipx_packages }}"
ansible.builtin.command: "{{ ansible_env.HOME }}/.local/bin/pipx install {{ item }}"
3 changes: 2 additions & 1 deletion tasks/psql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
repo: "deb http://apt.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg main"
state: present

- name: Install postgresql client
- name: Install PostgreSQL client
become: true
ansible.builtin.apt:
name: postgresql-client-15
cache_valid_time: "{{ cache_valid_time }}"
4 changes: 2 additions & 2 deletions tasks/pyenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
ansible.builtin.apt:
cache_valid_time: "{{ cache_valid_time }}"
name: "{{ item }}"
update_cache: true

- name: Clone/update pyenv
ansible.builtin.git:
dest: "{{ ansible_env.HOME }}/.pyenv"
repo: https://github.com/pyenv/pyenv.git
version: v{{ pyenv_version }}

- name: Check default Python version
changed_when: (global_python.rc != 0) or
(default_user_python_version not in global_python.stdout)
(python_version not in global_python.stdout)
failed_when: false
notify: Install/modify default Python for user
register: global_python
Expand Down
1 change: 1 addition & 0 deletions tasks/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
- vagrant
ansible.builtin.apt:
name: "{{ item }}"
cache_valid_time: "{{ cache_valid_time }}"

0 comments on commit 7a39705

Please sign in to comment.