diff --git a/.ansible-lint b/.ansible-lint index 9be5545..a6d1e2d 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -1,2 +1,4 @@ +--- exclude_paths: -- .travis.yml + - .travis.yml + - .ansible-lint diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4f128e5..f7502d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,51 +1,45 @@ -# -*- mode: yaml -*- -# vim:ts=2:sw=2:ai:si:syntax=yaml -################################ -# pre-commit hooks configuration -################################ --- - repos: - repo: https://github.com/pre-commit/pre-commit-hooks.git - rev: v2.2.3 + rev: v4.4.0 hooks: - id: check-executables-have-shebangs - id: check-byte-order-marker - id: check-case-conflict - id: check-merge-conflict - id: trailing-whitespace - args: ['--markdown-linebreak-ext=md'] + args: ["--markdown-linebreak-ext=md"] - id: end-of-file-fixer - id: mixed-line-ending - args: ['--fix=lf'] + args: ["--fix=lf"] - id: check-yaml - id: pretty-format-json - args: ['--autofix', '--indent=2', '--no-sort-keys'] + args: ["--autofix", "--indent=2", "--no-sort-keys"] - repo: https://github.com/adrienverge/yamllint.git - rev: v1.16.0 + rev: v1.29.0 hooks: - id: yamllint - repo: https://github.com/ansible/ansible-lint.git - rev: v4.1.0 + rev: v6.13.1 hooks: - id: ansible-lint files: \.(yaml|yml)$ - - repo: https://github.com/bemeurer/beautysh.git - rev: '4.1' + - repo: https://github.com/syntaqx/git-hooks + rev: v0.0.17 hooks: - - id: beautysh + - id: shellcheck files: (tests/run-.*|tests/update)$ - - repo: https://github.com/openstack-dev/bashate.git - rev: '0.6.0' + - repo: https://github.com/scop/pre-commit-shfmt + rev: v3.6.0-1 hooks: - - id: bashate + - id: shfmt files: (tests/run-.*|tests/update)$ - repo: https://github.com/igorshubovych/markdownlint-cli.git - rev: v0.17.0 + rev: v0.33.0 hooks: - id: markdownlint diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cc9d09..360137b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,44 +1,77 @@ # Changelog +## [2.0.0] - 2023-02-17 + +### Ansible compatibility + +- Require Ansible 2.9.22 +- Support Ansible 7.2.0 +- Use fully qualified collection names (FQCN) with builtin modules + +### Fixes + +- Use `become_user` instead of `become` when installing with Git by [@Hunsu] in [#6] +- Remove installer script checksum that causes issues [#10] + +[@hunsu]: https://github.com/Hunsu +[#6]: https://github.com/markosamuli/ansible-linuxbrew/pull/6 +[#10]: https://github.com/markosamuli/ansible-linuxbrew/issues/10 + +### Python compatibility + +- Use Python 3 on all test Docker images +- Drop support for EOL Python 2.7 + +### OS compatibility + +- Add support for Ubuntu 20.04 LTS and 22.04 LTS +- Add support for Debian 11 +- Add support for Fedora 37 and RedHat based-systems by [@aarey] in [#9] +- Drop support for Debian 11 +- Drop support for Ubuntu 16.04 LTS + +[@aarey]: https://github.com/aairey +[#9]: https://github.com/markosamuli/ansible-linuxbrew/pull/9 + ## [1.2.2] - 2020-09-06 ### Fixed -* Update `install.sh` checksum -* Create missing `var/homebrew/linked` directory -* Update `linuxbrew-core` repository URL +- Update `install.sh` checksum +- Create missing `var/homebrew/linked` directory +- Update `linuxbrew-core` repository URL ## [1.2.1] - 2020-09-05 ### Fixed -* Migrate to the new `install.sh` script +- Migrate to the new `install.sh` script ## [1.2.0] - 2019-10-25 ### Changes -* Add `linuxbrew_init_shell` variable to allow shell file modification to be +- Add `linuxbrew_init_shell` variable to allow shell file modification to be disabled. Fixes [#1] ## [1.1.1] - 2019-07-20 ### Fixes -* Updated `install.sh` checksum for the 2019-07-18 updated version. +- Updated `install.sh` checksum for the 2019-07-18 updated version. ## [1.1.0] - 2019-07-14 ### Changes -* Use Ansible tasks to clone the Homebrew Git repositories, create directories +- Use Ansible tasks to clone the Homebrew Git repositories, create directories and set permissions where possible instead of using the official installer bash script. ### Fixes -* Install installation dependencies. -* Update both `.bashrc` and `.zshrc` shell scripts. +- Install installation dependencies. +- Update both `.bashrc` and `.zshrc` shell scripts. ## [1.0.0] - 2019-01-13 diff --git a/Makefile b/Makefile index 75d757d..65fbe03 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,33 @@ -PRE_COMMIT_HOOKS=.git/hooks/pre-commit + +.DEFAULT_GOAL := help + +# Use VERBOSE=1 make to get verbose output +ifndef VERBOSE +.SILENT: +endif + +.PHONY: help +help: ## print this help + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort -d | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +PRE_COMMIT_HOOKS = .git/hooks/pre-commit + +TEST_IMAGES = $(shell ls tests/*/Dockerfile | xargs dirname | xargs basename) + +.PHONY: setup +setup: $(PRE_COMMIT_HOOKS) .PHONY: test -test: - @./tests/run-tests +test: ## run tests with all available Docker images + ./tests/run-tests + +.PHONY: $(TEST_IMAGES) +$(TEST_IMAGES): + ./tests/run-tests $@ .PHONY: lint lint: $(PRE_COMMIT_HOOKS) - @pre-commit run -a + pre-commit run -a $(PRE_COMMIT_HOOKS): - @pre-commit install + pre-commit install diff --git a/README.md b/README.md index a80f3fc..836b6d9 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,30 @@ using Travis CI on my OSS projects. I've tested the role up to Ansible 2.8 using local installation. +## Compatibility + +Run tests with a supported Docker image, for example with `bionic`: + +```bash +make bionic +``` + +| Release | Docker image | Ansible | +| ---------------- | ---------------------- | ---------------- | +| Ubuntu 18.04 LTS | [`bionic`][bionic] | `<2.12,>=2.9.22` | +| Ubuntu 20.04 LTS | [`focal`][focal] | `>=2.9.22` | +| Ubuntu 22.04 LTS | [`jammy`][jammy] | `>=2.9.22` | +| Debian 10 | [`buster`][buster] | `<2.12,>=2.9.22` | +| Debian 11 | [`bullseye`][bullseye] | `>=2.9.22` | +| Fedora 37 | [`fedora37`][fedora37] | `>=2.9.22` | + +[bionic]: tests/bionic/Dockerfile +[focal]: tests/focal/Dockerfile +[jammy]: tests/jammy/Dockerfile +[buster]: tests/buster/Dockerfile +[bullseye]: tests/buster/Dockerfile +[fedora37]: tests/fedora37/Dockerfile + ## Configuration By default, the role uses Ansible to clone the Homebrew Git repository and @@ -26,10 +50,12 @@ you need to enable this in the Ansible configuration: linuxbrew_use_installer: true ``` +The installer seems to be faster than the default Ansible installation method. + ## Role Variables Set `linuxbrew_init_shell` to `false` if you're for example managing your shell -rc files using your own .dotfiles repository. +init files using your own `.dotfiles` repository. ```yaml # Configure shell rc files diff --git a/defaults/main.yml b/defaults/main.yml index 0f7730c..52f6585 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,4 @@ --- - # Path to user home directory linuxbrew_home: "{{ ansible_env.HOME }}" diff --git a/meta/main.yml b/meta/main.yml index d3b6179..e67c981 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,23 +1,27 @@ # -*- mode: yaml -*- # vim:ts=2:sw=2:ai:si:syntax=yaml --- - galaxy_info: role_name: linuxbrew + namespace: markosamuli author: Marko Samuli Kirves - description: Install Linuxbrew - license: MIT - min_ansible_version: 2.6 + description: Install Homebrew on Linux + license: BSD + min_ansible_version: 2.9.22 github_branch: master platforms: - name: Ubuntu versions: - - xenial - bionic + - focal + - jammy - name: Debian versions: - buster - - stretch + - bullseye + - name: Fedora + versions: + - "37" galaxy_tags: - linuxbrew - homebrew diff --git a/tasks/install.yml b/tasks/install.yml deleted file mode 100644 index 73f275c..0000000 --- a/tasks/install.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- - -- name: Install dependencies on Debian based systems - include_tasks: install_debian.yml - when: "ansible_os_family == 'Debian' or ansible_distribution == 'Pengwin'" - -- name: Install with Git - include_tasks: install_with_git.yml - when: not linuxbrew_use_installer - -- name: Install using the installer script - include_tasks: install_with_installer.yml - when: linuxbrew_use_installer diff --git a/tasks/install_debian.yml b/tasks/install/debian.yml similarity index 87% rename from tasks/install_debian.yml rename to tasks/install/debian.yml index ce7162b..da68bc4 100644 --- a/tasks/install_debian.yml +++ b/tasks/install/debian.yml @@ -1,7 +1,6 @@ --- - - name: Install dependencies with APT - apt: + ansible.builtin.apt: name: "{{ linuxbrew_install_dependencies }}" when: linuxbrew_install_dependencies is defined become: true diff --git a/tasks/install/install.yml b/tasks/install/install.yml new file mode 100644 index 0000000..8dc8fff --- /dev/null +++ b/tasks/install/install.yml @@ -0,0 +1,16 @@ +--- +- name: Install dependencies on Debian based systems + ansible.builtin.include_tasks: debian.yml + when: "ansible_os_family == 'Debian' or ansible_distribution == 'Pengwin'" + +- name: Install dependencies on RedHat based systems + ansible.builtin.include_tasks: redhat.yml + when: "ansible_os_family == 'RedHat'" + +- name: Install with Git + ansible.builtin.include_tasks: with_git.yml + when: not linuxbrew_use_installer + +- name: Install using the installer script + ansible.builtin.include_tasks: with_installer.yml + when: linuxbrew_use_installer diff --git a/tasks/install/redhat.yml b/tasks/install/redhat.yml new file mode 100644 index 0000000..f3a7890 --- /dev/null +++ b/tasks/install/redhat.yml @@ -0,0 +1,7 @@ +--- +- name: Install dependencies with yum + ansible.builtin.yum: + name: "{{ linuxbrew_install_dependencies }}" + state: present + when: linuxbrew_install_dependencies is defined + become: true diff --git a/tasks/install_with_git.yml b/tasks/install/with_git.yml similarity index 75% rename from tasks/install_with_git.yml rename to tasks/install/with_git.yml index cfef894..43d79fb 100644 --- a/tasks/install_with_git.yml +++ b/tasks/install/with_git.yml @@ -1,23 +1,28 @@ --- +- name: Get current user + ansible.builtin.command: whoami + register: linuxbrew_whoami + changed_when: false + become: false - name: Set Linuxbrew user - set_fact: - linuxbrew_user: "{{ ansible_user }}" + ansible.builtin.set_fact: + linuxbrew_user: "{{ linuxbrew_whoami.stdout }}" when: linuxbrew_user is undefined - name: Get group for user {{ linuxbrew_user }} - command: id -g + ansible.builtin.command: id -g register: linuxbrew_user_group become_user: "{{ linuxbrew_user }}" changed_when: false - name: Set Linuxbrew group - set_fact: + ansible.builtin.set_fact: linuxbrew_group: "{{ linuxbrew_user_group.stdout }}" when: linuxbrew_group is undefined - name: Create Linuxbrew directory - file: + ansible.builtin.file: path: "{{ linuxbrew_prefix_shared }}" state: directory owner: "{{ linuxbrew_user }}" @@ -26,7 +31,7 @@ become: true - name: Create Linuxbrew directories - file: + ansible.builtin.file: path: "{{ linuxbrew_prefix_shared }}/{{ item }}" state: directory owner: "{{ linuxbrew_user }}" @@ -50,23 +55,23 @@ - Frameworks - name: Set path to Homebrew repository - set_fact: + ansible.builtin.set_fact: linuxbrew_repository: "{{ linuxbrew_prefix_shared }}/Homebrew" - name: Clone Homebrew repository - git: + ansible.builtin.git: repo: "{{ linuxbrew_brew_repo }}" dest: "{{ linuxbrew_repository }}" version: "{{ linuxbrew_brew_version }}" -- name: Clone Linuxbrew Core Tap repository - git: +- name: Clone Homebrew Core Tap repository + ansible.builtin.git: repo: "{{ linuxbrew_core_tap_repo }}" dest: "{{ linuxbrew_repository }}/Library/Taps/homebrew/homebrew-core" version: "{{ linuxbrew_core_tap_version }}" - name: Update permissions - file: + ansible.builtin.file: path: "{{ item }}" owner: "{{ linuxbrew_user }}" group: "{{ linuxbrew_group }}" @@ -76,21 +81,23 @@ - "{{ linuxbrew_repository }}/Library/Taps/homebrew/homebrew-core" - name: Create symlink to brew binary - file: + ansible.builtin.file: dest: "{{ linuxbrew_prefix_shared }}/bin/brew" src: "{{ linuxbrew_repository }}/bin/brew" state: "link" when: linuxbrew_prefix_shared != linuxbrew_repository - name: Path to portable-ruby vendor directory - set_fact: + ansible.builtin.set_fact: + # yamllint disable-line rule:line-length linuxbrew_ruby_current: "{{ linuxbrew_repository }}/vendor/portable-ruby/current" - name: Path to portable-ruby binary - set_fact: + ansible.builtin.set_fact: linuxbrew_ruby_path: "{{ linuxbrew_ruby_current }}/bin/ruby" - name: Update Homebrew to install portable Ruby - command: "{{ linuxbrew_prefix_shared }}/bin/brew update --force" + # yamllint disable-line rule:line-length + ansible.builtin.command: "{{ linuxbrew_prefix_shared }}/bin/brew update --force" args: creates: "{{ linuxbrew_ruby_path }}" diff --git a/tasks/install_with_installer.yml b/tasks/install/with_installer.yml similarity index 55% rename from tasks/install_with_installer.yml rename to tasks/install/with_installer.yml index 80cb924..3194556 100644 --- a/tasks/install_with_installer.yml +++ b/tasks/install/with_installer.yml @@ -1,27 +1,27 @@ --- - - name: Temporary directory - file: + ansible.builtin.file: path: "{{ linuxbrew_install_tmp }}" state: directory + mode: 0700 become: false -- name: Download Linuxbrew install script - get_url: +- name: Download Homebrew install script + ansible.builtin.get_url: url: "{{ linuxbrew_install_url }}" dest: "{{ linuxbrew_install_tmp }}/install.sh" - checksum: "{{ linuxbrew_install_checksum }}" - mode: 0777 + checksum: "{{ linuxbrew_install_checksum | default(omit) }}" + mode: 0700 become: false -- name: Install Linuxbrew - command: sh -c "{{ linuxbrew_install_tmp }}/install.sh" +- name: Install Homebrew with the installer + ansible.builtin.command: sh -c "{{ linuxbrew_install_tmp }}/install.sh" register: install_result changed_when: "install_result.rc == 0" become: false - name: Remove temporary directory - file: + ansible.builtin.file: path: "{{ linuxbrew_install_tmp }}" state: absent become: false diff --git a/tasks/main.yml b/tasks/main.yml index 0c8b297..e784e06 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,28 +2,28 @@ # tasks file for markosamuli.linuxbrew - name: Load variables for the target system - include_vars: "{{ item }}" + ansible.builtin.include_vars: "{{ item }}" with_first_found: - "os/{{ ansible_distribution }}.yml" - "os/{{ ansible_os_family }}.yml" - name: Check if Linuxbrew is already installed in {{ linuxbrew_prefix_shared }} - stat: + ansible.builtin.stat: path: "{{ linuxbrew_prefix_shared }}/bin/brew" register: linuxbrew_shared_st become: true - name: Check if Linuxbrew is already installed in {{ linuxbrew_prefix_user }} - stat: + ansible.builtin.stat: path: "{{ linuxbrew_prefix_user }}/bin/brew" register: linuxbrew_user_st become: false - name: Install Linuxbrew - include_tasks: install.yml + ansible.builtin.include_tasks: install/install.yml when: not linuxbrew_shared_st.stat.exists - and not linuxbrew_user_st.stat.exists + and not linuxbrew_user_st.stat.exists - name: Configure Linuxbrew in shell - include_tasks: shell.yml + ansible.builtin.include_tasks: shell/shell.yml when: linuxbrew_init_shell|bool diff --git a/tasks/shell/bash.yml b/tasks/shell/bash.yml new file mode 100644 index 0000000..c430a7c --- /dev/null +++ b/tasks/shell/bash.yml @@ -0,0 +1,139 @@ +--- +- name: Find .bash_profile and .profile files + block: + - name: Set path to .bash_profile + ansible.builtin.set_fact: + linuxbrew_bash_profile_path: "{{ linuxbrew_home }}/.bash_profile" + when: linuxbrew_bash_profile_path is undefined + + - name: Check whether .bash_profile exists + ansible.builtin.stat: + path: "{{ linuxbrew_bash_profile_path }}" + register: linuxbrew_bash_profile_st + + - name: Set path to .profile + ansible.builtin.set_fact: + linuxbrew_profile_path: "{{ linuxbrew_home }}/.profile" + when: linuxbrew_profile_path is undefined + + - name: Check whether .profile exists + ansible.builtin.stat: + path: "{{ linuxbrew_profile_path }}" + register: linuxbrew_profile_st + +- name: Configure .bash_profile (if it exists) + when: linuxbrew_bash_profile_st.stat.exists + block: + - name: Resolve .bash_profile symlink + ansible.builtin.set_fact: + # yamllint disable-line rule:line-length + linuxbrew_bash_profile_path: "{{ linuxbrew_bash_profile_st.stat.lnk_source }}" + when: + - linuxbrew_bash_profile_st.stat.exists + - linuxbrew_bash_profile_st.stat.islnk + + - name: Check whether Homebrew is loaded in .bash_profile + ansible.builtin.command: >- + grep -Fq 'brew shellenv' {{ linuxbrew_bash_profile_path }} + register: check_bash_profile + ignore_errors: true + changed_when: false + failed_when: false + when: linuxbrew_bash_profile_st.stat.exists + + - name: Load Homebrew in .bash_profile + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_bash_profile_path }}" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: + - linuxbrew_bash_profile_st.stat.exists + - check_bash_profile.rc != 0 + + - name: Create new .bash_profile + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_bash_profile_path }}" + create: true + mode: "0644" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: not linuxbrew_bash_profile_st.stat.exists + +- name: Configure .profile (if it exists) + when: not linuxbrew_bash_profile_st.stat.exists + block: + - name: Resolve .profile symlink + ansible.builtin.set_fact: + linuxbrew_profile_path: "{{ linuxbrew_profile_st.stat.lnk_source }}" + when: + - linuxbrew_profile_st.stat.exists + - linuxbrew_profile_st.stat.islnk + + - name: Check whether Homebrew is loaded in .profile + ansible.builtin.command: >- + grep -Fq 'brew shellenv' {{ linuxbrew_profile_path }} + register: check_profile + ignore_errors: true + changed_when: false + failed_when: false + when: linuxbrew_profile_st.stat.exists + + - name: Load Homebrew in .profile + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_profile_path }}" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: + - linuxbrew_profile_st.stat.exists + - check_profile.rc != 0 + + - name: Create new .profile + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_profile_path }}" + create: true + mode: "0644" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: not linuxbrew_profile_st.stat.exists + +- name: Configure .bashrc (if it exists) + block: + - name: Set path to .bashrc + ansible.builtin.set_fact: + linuxbrew_bashrc_path: "{{ linuxbrew_home }}/.bashrc" + when: linuxbrew_bashrc_path is undefined + + - name: Check whether .bashrc file exists + ansible.builtin.stat: + path: "{{ linuxbrew_bashrc_path }}" + register: linuxbrew_bashrc_st + + - name: Resolve .bashrc symlink + ansible.builtin.set_fact: + linuxbrew_bashrc_path: "{{ linuxbrew_bashrc_st.stat.lnk_source }}" + when: + - linuxbrew_bashrc_st.stat.exists + - linuxbrew_bashrc_st.stat.islnk + + - name: Check whether Homebrew is loaded in .bashrc + ansible.builtin.command: >- + grep -EFq 'brew shellenv' {{ linuxbrew_bashrc_path }} + register: check_bashrc_linuxbrew + ignore_errors: true + changed_when: false + failed_when: false + when: linuxbrew_bashrc_st.stat.exists + + - name: Load Homebrew in .bashrc + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_bashrc_path }}" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: + - linuxbrew_bashrc_st.stat.exists + - check_bashrc_linuxbrew.rc != 0 diff --git a/tasks/shell.yml b/tasks/shell/shell.yml similarity index 74% rename from tasks/shell.yml rename to tasks/shell/shell.yml index 84827c8..0cca6a3 100644 --- a/tasks/shell.yml +++ b/tasks/shell/shell.yml @@ -1,7 +1,6 @@ --- - - name: Set path to Linuxbrew prefix - set_fact: + ansible.builtin.set_fact: linuxbrew_prefix: "{{ item }}" with_first_found: - "{{ linuxbrew_prefix_shared }}" @@ -9,9 +8,9 @@ become: true - name: Load Linuxbrew in bash - include_tasks: shell_bash.yml + ansible.builtin.include_tasks: bash.yml when: linuxbrew_prefix is defined - name: Load Linuxbrew in zsh - include_tasks: shell_zsh.yml + ansible.builtin.include_tasks: zsh.yml when: linuxbrew_prefix is defined diff --git a/tasks/shell/zsh.yml b/tasks/shell/zsh.yml new file mode 100644 index 0000000..2cf63a8 --- /dev/null +++ b/tasks/shell/zsh.yml @@ -0,0 +1,78 @@ +--- +- name: Configure .zprofile + block: + - name: Set path to .zprofile + ansible.builtin.set_fact: + linuxbrew_zprofile_path: "{{ linuxbrew_home }}/.zprofile" + when: linuxbrew_zprofile_path is undefined + + - name: Check whether .zprofile exists + ansible.builtin.stat: + path: "{{ linuxbrew_zprofile_path }}" + register: linuxbrew_zprofile_st + + - name: Resolve .zprofile symlink + ansible.builtin.set_fact: + linuxbrew_zprofile_path: "{{ linuxbrew_zprofile_st.stat.lnk_source }}" + when: + - linuxbrew_zprofile_st.stat.exists + - linuxbrew_zprofile_st.stat.islnk + + - name: Check whether pyenv is loaded in .zprofile + ansible.builtin.command: >- + grep -Fq 'brew shellenv' {{ linuxbrew_zprofile_path }} + register: check_zprofile + ignore_errors: true + changed_when: false + failed_when: false + when: linuxbrew_zprofile_st.stat.exists + + - name: Configure .zprofile and create if missing + when: not linuxbrew_zprofile_st.stat.exists or check_zprofile.rc != 0 + block: + - name: Load Homebrew in .zprofile + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_zprofile_path }}" + create: true + mode: "0644" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + +- name: Configure .zshrc (if it exists) + block: + - name: Set path to .zshrc + ansible.builtin.set_fact: + linuxbrew_zshrc_path: "{{ linuxbrew_home }}/.zshrc" + when: linuxbrew_zshrc_path is undefined + + - name: Check whether .zshrc exists + ansible.builtin.stat: + path: "{{ linuxbrew_zshrc_path }}" + register: linuxbrew_zshrc_st + + - name: Resolve .zshrc symlink + ansible.builtin.set_fact: + linuxbrew_zshrc_path: "{{ linuxbrew_zshrc_st.stat.lnk_source }}" + when: + - linuxbrew_zshrc_st.stat.exists + - linuxbrew_zshrc_st.stat.islnk + + - name: Check whether pyenv is loaded in .zshrc + ansible.builtin.command: >- + grep -Fq 'brew shellenv' {{ linuxbrew_zshrc_path }} + register: check_zshrc_linuxbrew + ignore_errors: true + changed_when: false + failed_when: false + when: linuxbrew_zshrc_st.stat.exists + + - name: Load Homebrew in .zshrc + ansible.builtin.blockinfile: + dest: "{{ linuxbrew_zshrc_path }}" + marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" + block: | + eval $({{ linuxbrew_prefix }}/bin/brew shellenv) + when: + - linuxbrew_zshrc_st.stat.exists + - check_zshrc_linuxbrew.rc != 0 diff --git a/tasks/shell_bash.yml b/tasks/shell_bash.yml deleted file mode 100644 index 2d68da2..0000000 --- a/tasks/shell_bash.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- - -- name: Set path to .bashrc - set_fact: - linuxbrew_bashrc_path: "{{ linuxbrew_home }}/.bashrc" - when: linuxbrew_bashrc_path is undefined - -- name: Check whether .bashrc file exists - stat: - path: "{{ linuxbrew_bashrc_path }}" - register: linuxbrew_bashrc_st - -- name: Resolve .bashrc symlink - set_fact: - linuxbrew_bashrc_path: "{{ linuxbrew_bashrc_st.stat.lnk_source }}" - when: linuxbrew_bashrc_st.stat.exists and linuxbrew_bashrc_st.stat.islnk - -- name: Load Linuxbrew in .bashrc - blockinfile: - dest: "{{ linuxbrew_bashrc_path }}" - marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" - block: | - eval $({{ linuxbrew_prefix }}/bin/brew shellenv) - when: linuxbrew_bashrc_st.stat.exists diff --git a/tasks/shell_zsh.yml b/tasks/shell_zsh.yml deleted file mode 100644 index 6a34b6f..0000000 --- a/tasks/shell_zsh.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- - -- name: Set path to .zshrc - set_fact: - linuxbrew_zshrc_path: "{{ linuxbrew_home }}/.zshrc" - when: linuxbrew_zshrc_path is undefined - -- name: Check whether .zshrc exists - stat: - path: "{{ linuxbrew_zshrc_path }}" - register: linuxbrew_zshrc_st - -- name: Resolve .zshrc symlink - set_fact: - linuxbrew_zshrc_path: "{{ linuxbrew_zshrc_st.stat.lnk_source }}" - when: linuxbrew_zshrc_st.stat.exists and linuxbrew_zshrc_st.stat.islnk - -- name: Load Linuxbrew in .zshrc - blockinfile: - dest: "{{ linuxbrew_zshrc_path }}" - marker: "# {mark} ANSIBLE MANAGED BLOCK: linuxbrew" - block: | - eval $({{ linuxbrew_prefix }}/bin/brew shellenv) - when: linuxbrew_zshrc_st.stat.exists diff --git a/tests/Dockerfile.template b/tests/Dockerfile.template deleted file mode 100644 index 49dcca1..0000000 --- a/tests/Dockerfile.template +++ /dev/null @@ -1,37 +0,0 @@ -FROM %%FROM%% - -RUN apt-get update && apt-get install -y \ - python-minimal \ - python-pip \ - && rm -rf /var/lib/apt/lists/* - -ARG ansible_version="%%ANSIBLE_VERSION%%" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip install ansible${ANSIBLE_VERSION} - -RUN apt-get update && apt-get install -y \ - zsh \ - sudo \ - && rm -rf /var/lib/apt/lists/* - -RUN apt-get update && apt-get install -y \ - aptitude \ - && rm -rf /var/lib/apt/lists/* - -ARG user=%%USER%% -ARG repository=%%REPOSITORY%% - -# Create test user -RUN useradd -m ${user} -s /bin/bash \ - && echo "${user}:${user}" | chpasswd \ - && adduser ${user} sudo \ - && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers -RUN touch /home/${user}/.zshrc \ - && chown -R ${user}:${user} /home/${user} - -# Create directory for code -RUN mkdir -p /home/${user}/${repository} ; \ - chown -R ${user}:${user} /home/${user}/${repository} -VOLUME ["/home/${user}/${repository}"] - -CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/bionic/Dockerfile b/tests/bionic/Dockerfile index ef7e289..18ed548 100644 --- a/tests/bionic/Dockerfile +++ b/tests/bionic/Dockerfile @@ -1,37 +1,49 @@ FROM ubuntu:bionic RUN apt-get update && apt-get install -y \ - python-minimal \ - python-pip \ - && rm -rf /var/lib/apt/lists/* + ca-certificates \ + && rm -rf /var/lib/apt/lists/* -ARG ansible_version="<2.9.0" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip install ansible${ANSIBLE_VERSION} +# Use a maintained UK-based mirror with HTTPS support +ARG ubuntu_archive=https://mirror.pulsant.com/sites/ubuntu-archive/ +RUN sed -i "s~http://archive.ubuntu.com/ubuntu/~${ubuntu_archive}~g" /etc/apt/sources.list -RUN apt-get update && apt-get install -y \ - zsh \ - sudo \ - && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* +# Python 3.6.9 RUN apt-get update && apt-get install -y \ - aptitude \ - && rm -rf /var/lib/apt/lists/* + zsh \ + sudo \ + python3-minimal \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# Fixed in Python 3.7 +# https://github.com/pypa/pip/issues/10219 +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 + +# Ansible will require Python 3.8 or newer on the controller starting +# with Ansible 2.12. +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="<2.12,${ansible_version}" +RUN pip3 install ansible${ANSIBLE_VERSION} ARG user=test ARG repository=ansible-linuxbrew # Create test user RUN useradd -m ${user} -s /bin/bash \ - && echo "${user}:${user}" | chpasswd \ - && adduser ${user} sudo \ - && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + && echo "${user}:${user}" | chpasswd \ + && adduser ${user} sudo \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers RUN touch /home/${user}/.zshrc \ - && chown -R ${user}:${user} /home/${user} + && chown -R ${user}:${user} /home/${user} # Create directory for code RUN mkdir -p /home/${user}/${repository} ; \ - chown -R ${user}:${user} /home/${user}/${repository} + chown -R ${user}:${user} /home/${user}/${repository} VOLUME ["/home/${user}/${repository}"] # Make sure we have the latest packages diff --git a/tests/bullseye/Dockerfile b/tests/bullseye/Dockerfile new file mode 100644 index 0000000..b5ac400 --- /dev/null +++ b/tests/bullseye/Dockerfile @@ -0,0 +1,43 @@ +FROM debian:bullseye + +RUN apt-get update && apt-get install -y \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# Use HTTPS +RUN sed -i "s~http://~https://~g" /etc/apt/sources.list + +RUN apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* + +RUN apt-get update && apt-get install -y \ + zsh \ + sudo \ + python3-minimal \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN pip3 install ansible${ANSIBLE_VERSION} + +ARG user=test +ARG repository=ansible-linuxbrew + +# Create test user +RUN useradd -m ${user} -s /bin/bash \ + && echo "${user}:${user}" | chpasswd \ + && adduser ${user} sudo \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +RUN touch /home/${user}/.zshrc \ + && chown -R ${user}:${user} /home/${user} + +# Create directory for code +RUN mkdir -p /home/${user}/${repository} ; \ + chown -R ${user}:${user} /home/${user}/${repository} +VOLUME ["/home/${user}/${repository}"] + +# Make sure we have the latest packages +RUN apt-get update + +CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/buster/Dockerfile b/tests/buster/Dockerfile index 96a4179..00ad2bb 100644 --- a/tests/buster/Dockerfile +++ b/tests/buster/Dockerfile @@ -1,37 +1,43 @@ FROM debian:buster RUN apt-get update && apt-get install -y \ - python-minimal \ - python-pip \ - && rm -rf /var/lib/apt/lists/* + ca-certificates \ + && rm -rf /var/lib/apt/lists/* -ARG ansible_version="<2.9.0" -ENV ANSIBLE_VERSION="${ansible_version}" -RUN pip install ansible${ANSIBLE_VERSION} +# Use HTTPS +RUN sed -i "s~http://~https://~g" /etc/apt/sources.list -RUN apt-get update && apt-get install -y \ - zsh \ - sudo \ - && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* +# Python 3.7.3 RUN apt-get update && apt-get install -y \ - aptitude \ - && rm -rf /var/lib/apt/lists/* + zsh \ + sudo \ + python3-minimal \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# Ansible will require Python 3.8 or newer on the controller starting with +# Ansible 2.12 +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="<2.12,${ansible_version}" +RUN pip3 install ansible${ANSIBLE_VERSION} ARG user=test ARG repository=ansible-linuxbrew # Create test user RUN useradd -m ${user} -s /bin/bash \ - && echo "${user}:${user}" | chpasswd \ - && adduser ${user} sudo \ - && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + && echo "${user}:${user}" | chpasswd \ + && adduser ${user} sudo \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers RUN touch /home/${user}/.zshrc \ - && chown -R ${user}:${user} /home/${user} + && chown -R ${user}:${user} /home/${user} # Create directory for code RUN mkdir -p /home/${user}/${repository} ; \ - chown -R ${user}:${user} /home/${user}/${repository} + chown -R ${user}:${user} /home/${user}/${repository} VOLUME ["/home/${user}/${repository}"] # Make sure we have the latest packages diff --git a/tests/fedora37/Dockerfile b/tests/fedora37/Dockerfile new file mode 100644 index 0000000..c1b2249 --- /dev/null +++ b/tests/fedora37/Dockerfile @@ -0,0 +1,33 @@ +FROM fedora:37 + +RUN dnf -y update && dnf clean all + +# Python 3.11 +RUN dnf -y install \ + zsh \ + sudo \ + python3 \ + python3-pip \ + && dnf clean all + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN pip install ansible${ANSIBLE_VERSION} + +ARG user=test +ARG repository=ansible-linuxbrew + +# Create test user +RUN useradd -m -s /bin/bash ${user} \ + && echo "${user}:${user}" | chpasswd \ + && usermod -aG wheel ${user} \ + && echo '%wheel ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +RUN touch /home/${user}/.zshrc \ + && chown -R ${user}:${user} /home/${user} + +# Create directory for code +RUN mkdir -p /home/${user}/${repository} ; \ + chown -R ${user}:${user} /home/${user}/${repository} +VOLUME ["/home/${user}/${repository}"] + +CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/focal/Dockerfile b/tests/focal/Dockerfile new file mode 100644 index 0000000..1174cf5 --- /dev/null +++ b/tests/focal/Dockerfile @@ -0,0 +1,44 @@ +FROM ubuntu:focal + +RUN apt-get update && apt-get install -y \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# Use a maintained UK-based mirror with HTTPS support +ARG ubuntu_archive=https://mirror.pulsant.com/sites/ubuntu-archive/ +RUN sed -i "s~http://archive.ubuntu.com/ubuntu/~${ubuntu_archive}~g" /etc/apt/sources.list + +RUN apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* + +RUN apt-get update && apt-get install -y \ + zsh \ + sudo \ + python3-minimal \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN pip install ansible${ANSIBLE_VERSION} + +ARG user=test +ARG repository=ansible-linuxbrew + +# Create test user +RUN useradd -m ${user} -s /bin/bash \ + && echo "${user}:${user}" | chpasswd \ + && adduser ${user} sudo \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +RUN touch /home/${user}/.zshrc \ + && chown -R ${user}:${user} /home/${user} + +# Create directory for code +RUN mkdir -p /home/${user}/${repository} ; \ + chown -R ${user}:${user} /home/${user}/${repository} +VOLUME ["/home/${user}/${repository}"] + +# Make sure we have the latest packages +RUN apt-get update + +CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/inventory b/tests/inventory index 2fbb50c..537f4b0 100644 --- a/tests/inventory +++ b/tests/inventory @@ -1 +1 @@ -localhost +localhost ansible_python_interpreter=auto diff --git a/tests/jammy/Dockerfile b/tests/jammy/Dockerfile new file mode 100644 index 0000000..1ca6b46 --- /dev/null +++ b/tests/jammy/Dockerfile @@ -0,0 +1,44 @@ +FROM ubuntu:jammy + +RUN apt-get update && apt-get install -y \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# Use a maintained UK-based mirror with HTTPS support +ARG ubuntu_archive=https://mirror.pulsant.com/sites/ubuntu-archive/ +RUN sed -i "s~http://archive.ubuntu.com/ubuntu/~${ubuntu_archive}~g" /etc/apt/sources.list + +RUN apt-get update && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* + +RUN apt-get update && apt-get install -y \ + zsh \ + sudo \ + python3-minimal \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +ARG ansible_version=">=2.9.22" +ENV ANSIBLE_VERSION="${ansible_version}" +RUN pip install ansible${ANSIBLE_VERSION} + +ARG user=test +ARG repository=ansible-linuxbrew + +# Create test user +RUN useradd -m ${user} -s /bin/bash \ + && echo "${user}:${user}" | chpasswd \ + && adduser ${user} sudo \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +RUN touch /home/${user}/.zshrc \ + && chown -R ${user}:${user} /home/${user} + +# Create directory for code +RUN mkdir -p /home/${user}/${repository} ; \ + chown -R ${user}:${user} /home/${user}/${repository} +VOLUME ["/home/${user}/${repository}"] + +# Make sure we have the latest packages +RUN apt-get update + +CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" diff --git a/tests/run-tests b/tests/run-tests index 06c445b..09e69f8 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -1,15 +1,38 @@ #!/usr/bin/env bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_ROOT=$(dirname $DIR) +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT=$(dirname "${DIR}") -ROLE_NAME="$(basename $PROJECT_ROOT)" +REPO_NAME="$(basename "${PROJECT_ROOT}")" +ROLE_NAME="markosamuli.${REPO_NAME/ansible-/}" TEST_HOME=/home/test -### +# Ansible version to install on the Docker images +# Use PIP version specifiers: +# https://peps.python.org/pep-0440/#version-specifiers +ANSIBLE_VERSION=">=2.9.22" + +# Colour list copied from: +# https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux + +# Reset +Color_Off='\033[0m' # Text Reset + +# Bold +BPurple='\033[1;35m' # Purple + +image_msg() { + local image=$1 + shift + echo -e "${BPurple}[${image}] $*${Color_Off}" +} + # Detect Windows Subsystem for Linux -### -function detect_wsl { +detect_wsl() { + if [ ! -e /proc/version ]; then + is_wsl=0 + return + fi if grep -q Microsoft /proc/version; then echo "*** Windows Subsystem for Linux detected" is_wsl=1 @@ -18,91 +41,99 @@ function detect_wsl { fi } -### # Stop all containers -### -function finish { +finish() { local containers="" - containers=$(docker ps -q --filter=name=${ROLE_NAME}) - if [ ! -z "${containers}" ]; then - echo "*** Stop all test containers" + containers=$(docker ps -q --filter=name="${REPO_NAME}") + if [ -n "${containers}" ]; then + echo "*** Stop and remove all test containers" + # shellcheck disable=SC2086 docker stop ${containers} fi } -### # Stop container -### -function stop { +stop() { local image=$1 - local container_name=${ROLE_NAME}-${image}-tests - echo "*** Stop containers" - docker stop ${container_name} + local container_name=${REPO_NAME}-${image}-tests + echo "" + image_msg "${image}" "Stop and remove containers" + echo "" + docker stop "${container_name}" + sleep 1 } -### # Build image -### -function build { +build() { local image=$1 - local image_name=${ROLE_NAME}-${image} - echo "*** Build image" - docker build -t ${image_name} ./tests/${image} + local image_name=${REPO_NAME}-${image} + echo "" + image_msg "${image}" "Build image from tests/${image}/Dockerfile" + echo "" + docker build \ + --build-arg "ansible_version=${ANSIBLE_VERSION}" \ + -t "${image_name}" \ + "./tests/${image}" } -### # Start container in the background -### -function start { +start() { local image=$1 - local image_name=${ROLE_NAME}-${image} - local container_name=${ROLE_NAME}-${image}-tests - echo "*** Start container" + local image_name=${REPO_NAME}-${image} + local container_name=${REPO_NAME}-${image}-tests + echo "" + image_msg "${image}" "Start container ${container_name}" + echo "" docker run --rm -it -d \ - -v ${MOUNT_ROOT}:${TEST_HOME}/${ROLE_NAME} \ - --name ${container_name} \ - $image_name + -v "${MOUNT_ROOT}:${TEST_HOME}/${ROLE_NAME}" \ + -e "TEST_IMAGE=${image}" \ + --name "${container_name}" \ + "$image_name" } -### -# Run tests in the container -### -function run_tests_with_git { +run_tests_with_git() { local image=$1 - local container_name=${ROLE_NAME}-${image}-tests - echo "*** Run tests installing with Ansible from Git" + local container_name=${REPO_NAME}-${image}-tests + echo "" + image_msg "${image}" "Run tests installing with Ansible from Git" + echo "" docker exec -it \ --user test \ - ${container_name} \ - ${TEST_HOME}/${ROLE_NAME}/tests/run-tests-with-git + "${container_name}" \ + "${TEST_HOME}/${ROLE_NAME}/tests/run-tests-with-git" } -### -# Run tests in the container -### -function run_tests_with_installer { +run_tests_with_installer() { local image=$1 - local container_name=${ROLE_NAME}-${image}-tests - echo "*** Run tests installing with the Linuxbrew installer" + local container_name=${REPO_NAME}-${image}-tests + echo "" + image_msg "${image}" "Run tests installing with the Linuxbrew installer" + echo "" docker exec -it \ --user test \ - ${container_name} \ - ${TEST_HOME}/${ROLE_NAME}/tests/run-tests-with-installer + "${container_name}" \ + "${TEST_HOME}/${ROLE_NAME}/tests/run-tests-with-installer" } trap finish EXIT detect_wsl -cd $DIR +cd "${DIR}" || { + echo "${DIR} not found" + exit 1 +} -images=( "$@" ) +images=("$@") if [ ${#images[@]} -eq 0 ]; then - images=( */Dockerfile ) - images=( "${images[@]/\/Dockerfile/}" ) + images=(*/Dockerfile) + images=("${images[@]/\/Dockerfile/}") fi -cd $PROJECT_ROOT +cd "${PROJECT_ROOT}" || { + echo "${PROJECT_ROOT} not found" + exit 1 +} if [ "${is_wsl}" == "1" ]; then MOUNT_ROOT="$(pwd -P | sed 's~/mnt/c/~c:/~')" @@ -113,17 +144,17 @@ fi set -e for i in "${images[@]}"; do - build $i + build "$i" done for i in "${images[@]}"; do - start $i - run_tests_with_git $i - stop $i + start "$i" + run_tests_with_git "$i" + stop "$i" done for i in "${images[@]}"; do - start $i - run_tests_with_installer $i - stop $i + start "$i" + run_tests_with_installer "$i" + stop "$i" done diff --git a/tests/run-tests-with-git b/tests/run-tests-with-git index d1b9715..39bd6da 100755 --- a/tests/run-tests-with-git +++ b/tests/run-tests-with-git @@ -1,7 +1,7 @@ #!/usr/bin/env bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_ROOT=$(dirname $DIR) +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT=$(dirname "$DIR") set -e @@ -13,9 +13,10 @@ extra_vars=$(printf ",%s" "${ansible_vars[@]}") extra_vars="{${extra_vars:1}}" # Paths in which Ansible will search for Roles -export ANSIBLE_ROLES_PATH=$(dirname $PROJECT_ROOT) +ANSIBLE_ROLES_PATH=$(dirname "$PROJECT_ROOT") +export ANSIBLE_ROLES_PATH -cd $PROJECT_ROOT +cd "$PROJECT_ROOT" echo "*** Check syntax" @@ -24,16 +25,32 @@ ansible-playbook tests/test.yml -i tests/inventory --syntax-check echo "*** Run Ansible playbook" ansible-playbook tests/test.yml -i tests/inventory --connection=local \ + -v \ -e "${extra_vars}" +run_status=$? +if [[ ${run_status} -eq 0 ]]; then + echo 'Run: pass' +else + echo 'Run: fail' + exit 1 +fi echo "*** Idempotence test" ansible-playbook tests/test.yml -i tests/inventory --connection=local \ - -e "${extra_vars}" \ - | grep -q 'changed=0.*failed=0' \ - && (echo 'Idempotence test: pass' && exit 0) \ - || (echo 'Idempotence test: fail' && exit 1) - -echo "*** Verify installed Linuxbrew version" - -bash -c 'command -v brew && brew --version' + -e "${extra_vars}" | + grep -q 'changed=0.*failed=0' +idempotence_status=$? +if [[ $idempotence_status -eq 0 ]]; then + echo 'Idempotence test: pass' +else + echo 'Idempotence test: fail' + exit 1 +fi + +echo "*** Ansible playbooks completed on image ${TEST_IMAGE}" + +echo "*** Verify installed Linuxbrew version in bash" +bash -i -c 'command -v brew && brew --version' + +echo "*** Tests completed on image ${TEST_IMAGE}" diff --git a/tests/run-tests-with-installer b/tests/run-tests-with-installer index 24b0634..a050add 100755 --- a/tests/run-tests-with-installer +++ b/tests/run-tests-with-installer @@ -1,7 +1,7 @@ #!/usr/bin/env bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_ROOT=$(dirname $DIR) +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT=$(dirname "$DIR") set -e @@ -13,9 +13,10 @@ extra_vars=$(printf ",%s" "${ansible_vars[@]}") extra_vars="{${extra_vars:1}}" # Paths in which Ansible will search for Roles -export ANSIBLE_ROLES_PATH=$(dirname $PROJECT_ROOT) +ANSIBLE_ROLES_PATH=$(dirname "$PROJECT_ROOT") +export ANSIBLE_ROLES_PATH -cd $PROJECT_ROOT +cd "$PROJECT_ROOT" echo "*** Check syntax" @@ -24,16 +25,32 @@ ansible-playbook tests/test.yml -i tests/inventory --syntax-check echo "*** Run Ansible playbook" ansible-playbook tests/test.yml -i tests/inventory --connection=local \ + -v \ -e "${extra_vars}" +run_status=$? +if [[ ${run_status} -eq 0 ]]; then + echo 'Run: pass' +else + echo 'Run: fail' + exit 1 +fi echo "*** Idempotence test" ansible-playbook tests/test.yml -i tests/inventory --connection=local \ - -e "${extra_vars}" \ - | grep -q 'changed=0.*failed=0' \ - && (echo 'Idempotence test: pass' && exit 0) \ - || (echo 'Idempotence test: fail' && exit 1) - -echo "*** Verify installed Linuxbrew version" - -bash -c 'command -v brew && brew --version' + -e "${extra_vars}" | + grep -q 'changed=0.*failed=0' +idempotence_status=$? +if [[ $idempotence_status -eq 0 ]]; then + echo 'Idempotence test: pass' +else + echo 'Idempotence test: fail' + exit 1 +fi + +echo "*** Ansible playbooks completed on image ${TEST_IMAGE}" + +echo "*** Verify installed Linuxbrew version in bash" +bash -i -c 'command -v brew && brew --version' + +echo "*** Tests completed on image ${TEST_IMAGE}" diff --git a/tests/test.yml b/tests/test.yml index 1dc1842..37c8df6 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,6 +1,6 @@ --- - - hosts: localhost remote_user: root + name: Install Homebrew on Linux roles: - - ansible-linuxbrew + - markosamuli.linuxbrew diff --git a/tests/update b/tests/update deleted file mode 100755 index 6cb97b7..0000000 --- a/tests/update +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -user="test" -repository="$(basename $(dirname $(pwd)))" -ansible_version="<2.9.0" - -image="ubuntu" -ubuntu_releases=(xenial bionic) -for tag in "${ubuntu_releases[@]}"; do - dir="${tag}" - mkdir -p "${dir}" - echo "*** Updating $dir/Dockerfile" - sed -r \ - -e 's!%%FROM%%!'"$image:$tag"'!g' \ - -e 's!%%USER%%!'"$user"'!g' \ - -e 's!%%REPOSITORY%%!'"$repository"'!g' \ - -e 's!%%ANSIBLE_VERSION%%!'"$ansible_version"'!g' \ - "Dockerfile.template" > "$dir/Dockerfile" -done - -image="debian" -debian_releases=(stretch buster) -for tag in "${debian_releases[@]}"; do - dir="${tag}" - mkdir -p "${dir}" - echo "*** Updating $dir/Dockerfile" - sed -r \ - -e 's!%%FROM%%!'"$image:$tag"'!g' \ - -e 's!%%USER%%!'"$user"'!g' \ - -e 's!%%REPOSITORY%%!'"$repository"'!g' \ - -e 's!%%ANSIBLE_VERSION%%!'"$ansible_version"'!g' \ - "Dockerfile.template" > "$dir/Dockerfile" -done diff --git a/vars/main.yml b/vars/main.yml index ffa2ad6..30f8b7d 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -13,4 +13,3 @@ linuxbrew_core_tap_version: master # Linuxbrew installer script linuxbrew_install_tmp: "/tmp/linuxbrew" linuxbrew_install_url: "https://raw.githubusercontent.com/Homebrew/install/master/install.sh" -linuxbrew_install_checksum: "sha256:45c12bcd7765986674142230fc0860f5274903adbe37d582e5537771a1bae0b8" diff --git a/vars/os/Debian.yml b/vars/os/Debian.yml index 48b78dd..71240d4 100644 --- a/vars/os/Debian.yml +++ b/vars/os/Debian.yml @@ -1,7 +1,10 @@ --- - linuxbrew_install_dependencies: - git - curl - build-essential - locales + + # ps is not installed on the buster Docker image + # https://github.com/Homebrew/brew/blob/master/Library/Homebrew/cmd/shellenv.sh + - procps diff --git a/vars/os/RedHat.yml b/vars/os/RedHat.yml new file mode 100644 index 0000000..671f4bd --- /dev/null +++ b/vars/os/RedHat.yml @@ -0,0 +1,10 @@ +--- +# RedHat dependencies from: +# https://github.com/markosamuli/ansible-linuxbrew/pull/9 +linuxbrew_install_dependencies: + - "@Development Tools" + - git + - curl + - procps-ng + - file + - libxcrypt-compat