Skip to content

Commit

Permalink
refactor: setup script with pyenv and virtualenv install
Browse files Browse the repository at this point in the history
Additional options for enabling and disabling Ansible installation
options.

Support for installing into the local pyenv development environment.

Split requirements.txt and requirements.dev.txt files.
  • Loading branch information
markosamuli committed Nov 23, 2019
1 parent d44658d commit deafcae
Show file tree
Hide file tree
Showing 5 changed files with 704 additions and 250 deletions.
43 changes: 20 additions & 23 deletions Makefile
Expand Up @@ -15,6 +15,10 @@ default: help
help: ## print this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: setup
setup: ## run setup with default options
@./setup

# Get paths to pyenv and Python commmands
PYENV_BIN = $(shell command -v pyenv 2>/dev/null)
PYTHON_BIN = $(shell command -v python 2>/dev/null)
Expand Down Expand Up @@ -59,37 +63,21 @@ endif
endif

.PHONY: setup-requirements
setup-requirements: setup-pyenv-virtualenv ## setup development requirements
setup-requirements: setup-pyenv-virtualenv ## setup requirements for running the scripts
@pip install -r requirements.txt

.PHONY: setup-dev-requirements
setup-dev-requirements: setup-pyenv-virtualenv ## setup development requirements
@pip install -r requirements.dev.txt

PRE_COMMIT_INSTALLED = $(shell pre-commit --version 2>&1 | head -1 | grep -q 'pre-commit 1' && echo true)

.PHONY: setup-pre-commit
setup-pre-commit: ## setup pre-commit if not installed
ifneq ($(PRE_COMMIT_INSTALLED),true)
@$(MAKE) setup-requirements
@$(MAKE) setup-dev-requirements
endif

.PHONY: setup-ansible
setup-ansible: ## setup Ansible from package manager without roles or running playbooks
@./setup \
--reinstall-ansible \
--disable-ansible-pypi \
--no-run-playbook \
--no-install-roles \
--print-versions \
--verbose

.PHONY: setup-ansible-pypi
setup-ansible-pypi: ## setup Ansible from PyPI without roles or running playbooks
@./setup \
--reinstall-ansible \
--enable-ansible-pypi \
--no-run-playbook \
--no-install-roles \
--print-versions \
--verbose

.PHONY: lint
lint: pre-commit ## lint source code

Expand All @@ -107,9 +95,18 @@ endif
travis-lint: setup-pre-commit ## lint .travis.yml file
@pre-commit run -a travis-lint -v

.PHONY: setup-ansible
install-ansible: ## install Ansible without roles or running playbooks
@./setup \
--install-ansible \
--no-run-playbook \
--no-install-roles \
--print-versions \
--verbose

.PHONY: install-roles
install-roles: ## install Ansible roles
@./setup -n
@./setup --no-run-playbook

.PHONY: clean-roles
clean-roles: setup-requirements ## remove outdated Ansible roles
Expand Down
110 changes: 74 additions & 36 deletions README.md
Expand Up @@ -25,36 +25,6 @@ See [markosamuli/macos-machine] for my macOS setup.
[Ansible]: https://www.ansible.com/
[markosamuli/macos-machine]: https://github.com/markosamuli/macos-machine

## Ansible version

The setup script will install Ansible using APT from [Ansible PPAs] if
the `ansible` command is not found on your system.

If an acceptable Ansible APT package installation candidate can't be found
the setup script will try to install Ansible with PIP in a local virtuelenv.

If `virtuelenv` can't be found the setup script the setup will fail.

You can define `MACHINE_ANSIBLE_VERSION` environment variable to change
the installed version.

Example to use Ansible 2.8:

```bash
export MACHINE_ANSIBLE_VERSION=2.8
```

| Version | PPA |
|---------|-----|
| `2.7` | [ansible/ansible-2.7] |
| `2.8` (default) | [ansible/ansible-2.8] |
| `2.9` | [ansible/ansible-2.9] |

[Ansible PPAs]: https://launchpad.net/~ansible
[ansible/ansible-2.7]: https://launchpad.net/~ansible/+archive/ubuntu/ansible-2.7
[ansible/ansible-2.8]: https://launchpad.net/~ansible/+archive/ubuntu/ansible-2.8
[ansible/ansible-2.9]: https://launchpad.net/~ansible/+archive/ubuntu/ansible-2.9

### Ubuntu

This setup has been tested on the [Ubuntu] [16.04 LTS (Xenial Xerus)]
Expand Down Expand Up @@ -140,6 +110,80 @@ Ansible Playbook with `--extra-vars`.

[machine.yaml]: machine.yaml

## Ansible

The setup script will try to install Ansible

### Ansible version

Ansible version 2.8 is installed by default.

You can define `MACHINE_ANSIBLE_VERSION` environment variable to change
the installed version.

Example to use Ansible 2.9 instead of Ansible 2.8:

```bash
export MACHINE_ANSIBLE_VERSION=2.9
```

### Force Ansible reinstall

To remove existing Ansible versions and force installation of Ansible, you
can use the `--reinstall-ansible` argument, for example:

```bash
./setup --reinstall-ansible
```

### Installing Ansible with APT

The setup script will install Ansible using APT from [Ansible PPAs] if
the `ansible` command is not found on your system.

| Version | PPA |
|---------|-----|
| `2.7` | [ansible/ansible-2.7] |
| `2.8` (default) | [ansible/ansible-2.8] |
| `2.9` | [ansible/ansible-2.9] |

[Ansible PPAs]: https://launchpad.net/~ansible
[ansible/ansible-2.7]: https://launchpad.net/~ansible/+archive/ubuntu/ansible-2.7
[ansible/ansible-2.8]: https://launchpad.net/~ansible/+archive/ubuntu/ansible-2.8
[ansible/ansible-2.9]: https://launchpad.net/~ansible/+archive/ubuntu/ansible-2.9

### Installing Ansible from PyPI into virtualenv

If an acceptable Ansible APT package installation candidate can't be found
the setup script will try to install Ansible with [pip] in a local virtuelenv.

If [virtuelenv] can't be found the setup script the setup will fail.

You can disable installation from PyPI with `--disable-ansible-pypi` argument,
for example:

```bash
./setup --disable-ansible-pypi
```

[pip]: https://pypi.org/project/pip/
[virtuelenv]: https://virtualenv.pypa.io/en/latest/

### Installing Ansible from PyPI into pyenv environment

If the user has set up a local development environment with [pyenv] and this is
defined in a `.python-version` file in the repository root, the setup script
will install Ansible into this environment.

Same as with the local virtualenv, you can disable installation from PyPI
with `--disable-ansible-pypi` argument, for example:

```bash
./setup --disable-ansible-pypi
```

[pyenv]: https://github.com/pyenv/pyenv

## Software installed by the playbooks

### Homebrew on Linux (aka Linuxbrew)
Expand Down Expand Up @@ -571,12 +615,6 @@ make clean-roles

## Development

Fix ansible-lint installation issues:

```bash
pip install virtualenv==16.3.0
```

Install [pre-commit] hooks:

```bash
Expand Down
2 changes: 2 additions & 0 deletions requirements.dev.txt
@@ -0,0 +1,2 @@
pre-commit==1.20.0
virtualenv==16.3.0
2 changes: 0 additions & 2 deletions requirements.txt
@@ -1,3 +1 @@
pre-commit==1.20.0
PyYAML<6,>=5.1
virtualenv==16.3.0

0 comments on commit deafcae

Please sign in to comment.