diff --git a/.ansible-lint b/.ansible-lint index a3ae50d..a0d5d0b 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -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: diff --git a/README.md b/README.md index c3adb84..ae09646 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 diff --git a/defaults/main.yml b/defaults/main.yml index 4f169d4..effa8bf 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 diff --git a/handlers/main.yml b/handlers/main.yml index 6d6eacf..27ceedd 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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 diff --git a/tasks/apt-upgrade.yml b/tasks/apt-upgrade.yml index d9aa4fd..123606c 100644 --- a/tasks/apt-upgrade.yml +++ b/tasks/apt-upgrade.yml @@ -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 diff --git a/tasks/apt.yml b/tasks/apt.yml index 429d3e8..944d000 100644 --- a/tasks/apt.yml +++ b/tasks/apt.yml @@ -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 }}" diff --git a/tasks/asdf.yml b/tasks/asdf.yml index 6374902..1ae4654 100644 --- a/tasks/asdf.yml +++ b/tasks/asdf.yml @@ -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: @@ -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 }} diff --git a/tasks/docker.yml b/tasks/docker.yml index 60e2b72..fbfdd2a 100644 --- a/tasks/docker.yml +++ b/tasks/docker.yml @@ -23,6 +23,8 @@ - docker-compose-plugin ansible.builtin.apt: name: "{{ item }}" + cache_valid_time: "{{ cache_valid_time }}" + - name: Create docker group become: true diff --git a/tasks/hstr.yml b/tasks/hstr.yml index 993ab77..64bea7c 100644 --- a/tasks/hstr.yml +++ b/tasks/hstr.yml @@ -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: diff --git a/tasks/main.yml b/tasks/main.yml index 51cde47..6453385 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -16,7 +16,7 @@ tags: - docker -- name: Add postgres +- name: Add PostgreSQL tags: - psql ansible.builtin.include_tasks: diff --git a/tasks/pipx.yml b/tasks/pipx.yml index 634c9af..b0c8e34 100644 --- a/tasks/pipx.yml +++ b/tasks/pipx.yml @@ -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 }}" diff --git a/tasks/psql.yml b/tasks/psql.yml index 8279062..2d45096 100644 --- a/tasks/psql.yml +++ b/tasks/psql.yml @@ -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 }}" diff --git a/tasks/pyenv.yml b/tasks/pyenv.yml index f8b8442..47b74bf 100644 --- a/tasks/pyenv.yml +++ b/tasks/pyenv.yml @@ -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 diff --git a/tasks/vagrant.yml b/tasks/vagrant.yml index f6472c8..8097600 100644 --- a/tasks/vagrant.yml +++ b/tasks/vagrant.yml @@ -19,3 +19,4 @@ - vagrant ansible.builtin.apt: name: "{{ item }}" + cache_valid_time: "{{ cache_valid_time }}"