Skip to content

Commit

Permalink
Merge branch 'feature/refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
naftulikay committed Jul 29, 2019
2 parents 8e3d253 + 58c8dd5 commit 1b928a5
Show file tree
Hide file tree
Showing 37 changed files with 257 additions and 327 deletions.
16 changes: 9 additions & 7 deletions .gitignore
@@ -1,8 +1,10 @@
# python
*.pyc
*.pyo
__pycache__
# Ansible
.ansible/galaxy-roles
.ansible/roles
*.retry

# vagrant
/.ansible
/.vagrant
tests/.ansible/

# Vagrant
.vagrant/
*-VBoxSVC-*.log
25 changes: 9 additions & 16 deletions .travis.yml
@@ -1,24 +1,17 @@
---
dist: trusty
sudo: required
sudo: false

matrix:
fast_finish: true
language: python
python: 3.6
cache: pip

services:
- docker
install: pip install -r requirements.txt

env:
global: # applied to every run
ROLE_NAME: python-dev

matrix: # each entry is its own run
- IMAGE_NAME: naftulikay/centos-vm:7
- IMAGE_NAME: naftulikay/xenial-vm:latest
- IMAGE_NAME: naftulikay/trusty-vm:latest

script: make test-clean
script: travis-pls make test

notifications:
email: { on_success: never, on_failure: never }
email:
on_success: never
on_failure: never
webhooks: https://galaxy.ansible.com/api/v1/notifications/
13 changes: 13 additions & 0 deletions LICENSE-APACHE
@@ -0,0 +1,13 @@
Copyright © 2019 Naftuli Kay

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
14 changes: 14 additions & 0 deletions LICENSE-MIT
@@ -0,0 +1,14 @@
Copyright © 2019 Naftuli Kay

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
84 changes: 12 additions & 72 deletions Makefile
@@ -1,80 +1,20 @@
#!/usr/bin/make -f
ROLE_NAME:=python-dev
MOUNT_PATH:=/etc/ansible/roles/$(ROLE_NAME)

# TODO trusty needs not systemd flags
SYSTEMD_FLAGS:=--privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro
SHELL:=$(shell which bash)

LOCAL_FLAGS:=-v $(shell pwd):$(MOUNT_PATH):ro -v $(shell pwd)/ansible.cfg:/etc/ansible/ansible.cfg:ro
SELINUX_FLAGS:=
clean:
@docker-compose down

CONTAINER_ID_DIR:=/tmp/container/$(IMAGE_NAME)
CONTAINER_ID_FILE:=$(CONTAINER_ID_DIR)/id
CONTAINER_ID:=$(shell cat "$(CONTAINER_ID_FILE)" 2>/dev/null)
start:
@docker-compose up -d

validate:
ifeq ($(IMAGE_NAME),)
@echo "IMAGE_NAME is undefined, please define it."
@exit 1
endif
ifeq ($(ROLE_NAME),)
@echo "ROLE_NAME is undefined, please define it."
@exit 1
endif
pip:
@pip install -q $(shell test -z "$$TRAVIS" && echo "--user") -r requirements.txt ; \

# get status of the vm-like container
status: validate
@if [ -z "$(CONTAINER_ID)" ]; then \
echo "Container Not Running" ; \
exit 1 ; \
else \
echo "Container Running" ; \
fi
install: pip

start: validate
@if [ ! -z "$(CONTAINER_ID)" ]; then \
echo "ERROR: Container Already Running: $(CONTAINER_ID)" >&2 ; \
exit 1 ; \
fi
@# start it
@echo "Starting the Container:"
@test -d "$(CONTAINER_ID_DIR)" || mkdir -p "$(CONTAINER_ID_DIR)"
docker pull $(IMAGE_NAME)
docker pull docker:stable-dind
docker run -d --privileged --name dind docker:stable-dind
docker run -d --link dind:docker $(SYSTEMD_FLAGS) $(LOCAL_FLAGS) $$(test -d /etc/selinux && echo $(SELINUX_FLAGS)) $(IMAGE_NAME) > $(CONTAINER_ID_FILE)
unittest: pip
@if [ -e tests.py ]; then python tests.py -vvv ; fi

stop: validate
@if [ -z "$(CONTAINER_ID)" ] && ! docker ps --filter id=$(CONTAINER_ID) --format '{{.ID}}' | grep -qP '.*' ; then \
echo "ERROR: Container Not Running" >&2 ; \
rm -f $(CONTAINER_ID_FILE) ; \
exit 0 ; \
fi ; \
docker kill $(CONTAINER_ID) > /dev/null ; \
docker rm -f -v $(CONTAINER_ID) > /dev/null ; \
docker rm -f -v dind ; \
rm -f $(CONTAINER_ID_FILE) ; \
echo "Stopped Container $(CONTAINER_ID)"

restart:
$(MAKE) stop
$(MAKE) start

shell: status
docker exec -it $(CONTAINER_ID) /bin/bash -

test:
@if [ -z "$(CONTAINER_ID)" ]; then \
echo "ERROR: Container Not Running" >&2 ; \
exit 1 ; \
fi
@# need a way to ask systemd in the container to wait until all services up
docker exec $(CONTAINER_ID) ansible --version
docker exec $(CONTAINER_ID) wait-for-boot
docker exec $(CONTAINER_ID) ansible-galaxy install --force -r ${MOUNT_PATH}/tests/requirements.yml
docker exec $(CONTAINER_ID) env ANSIBLE_FORCE_COLOR=yes \
ansible-playbook $(MOUNT_PATH)/tests/playbook.yml

test-clean:
$(MAKE) restart
$(MAKE) test
test: install start unittest
@make -C tests/ test
67 changes: 7 additions & 60 deletions README.md
@@ -1,70 +1,17 @@
# ansible-role-python-dev [![Build Status][img-build-status]][build-status]
# ansible-role-python-dev [![Build Status][travis.svg]][travis]

Installs and configures a Python development environment for a given user using [`pyenv`][pyenv].

Available on Ansible Galaxy at [`naftulikay.python-dev`][galaxy].

## Requirements

Officially tested operating systems are listed in the Galaxy manifest.

## Role Variables

<dl>
<dt><code>python_user</code></dt>
<dd>User to install Python tools for. Required.</dd>
<dt><code>python_version</code></dt>
<dd>Version of Python to install. Defaults to 2.7.</dd>
<dt><code>addtl_python_system_packages</code></dt>
<dd>A list of additional system packages to install.</dd>
<dt><code>addtl_python_pip_system_packages</code></dt>
<dd>A list of additional Python system packages to install via pip.</dd>
<dt><code>addtl_python_pip_user_packages</code></dt>
<dd>A list of additional Python user packages to install via pip.</dd>
<dl>

## Dependencies

None.

## Example Playbook

Here are some example playbooks to get started with.

### Defaults

Simply get a Python development environment installed:

```yaml
---
- name: install
hosts: all
become: true
roles:
- role: python-dev
python_user: vagrant
```

### Install a Specific Version

Install a specific version of Python:

```yaml
---
- name: install
hosts: all
become: true
roles:
- role: python-dev
python_user: vagrant
python_version: '3.5'
```

## License

MIT
Licensed at your discretion under either:

- [Apache Software License, Version 2.0](./LICENSE-APACHE)
- [MIT License](./LICENSE-MIT)

[build-status]: https://travis-ci.org/naftulikay/ansible-role-python-dev
[img-build-status]: https://travis-ci.org/naftulikay/ansible-role-python-dev.svg?branch=master
[galaxy]: https://galaxy.ansible.com/naftulikay/python-dev/
[pyenv]: https://github.com/pyenv/pyenv
[travis.svg]: https://travis-ci.org/naftulikay/ansible-role-python-dev.svg?branch=master
[travis]: https://travis-ci.org/naftulikay/ansible-role-python-dev
4 changes: 2 additions & 2 deletions Vagrantfile
Expand Up @@ -11,7 +11,7 @@ VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "bento/centos-7.4"
config.vm.hostname = "devel"
config.vm.hostname = File.expand_path(File.dirname(__FILE__)).split('/')[-1]

# Create a private network, which allows host-only access to the machine
# using a specific IP.
Expand All @@ -33,4 +33,4 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# allow passing ansible args from environment variable
ansible.raw_arguments = Shellwords::shellwords(ENV.fetch("ANSIBLE_ARGS", ""))
end
end
end
4 changes: 1 addition & 3 deletions ansible.cfg
@@ -1,5 +1,3 @@
[defaults]
retry_files_enabled = false

[galaxy]
role_skeleton_ignore = ^.git(ignore)?$,^\.travis\.yml$,^tests,^(Vagrantfile|vagrant\.yml|\.vagrant)$,^Makefile$
roles_path = .ansible/galaxy-roles
2 changes: 2 additions & 0 deletions defaults/main.yml
@@ -1 +1,3 @@
---
python_user: null
python_version: null
42 changes: 42 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,42 @@
---
version: '3'
services:
bionic:
container_name: bionic
image: naftulikay/bionic-vm:latest
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
stop_grace_period: 1s

centos7:
container_name: centos7
image: naftulikay/centos7-vm:latest
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
stop_grace_period: 1s

juno:
container_name: juno
image: naftulikay/juno-vm:latest
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
stop_grace_period: 1s

loki:
container_name: loki
image: naftulikay/loki-vm:latest
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
stop_grace_period: 1s

xenial:
container_name: xenial
image: naftulikay/xenial-vm:latest
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
stop_grace_period: 1s
1 change: 0 additions & 1 deletion handlers/main.yml

This file was deleted.

4 changes: 4 additions & 0 deletions meta/main.yml
@@ -1,6 +1,7 @@
---
galaxy_info:
name: python-dev
src: naftulikay.python-dev
author: Naftuli Kay
description: Install and configure a Python development environment on a system.

Expand All @@ -15,3 +16,6 @@ galaxy_info:
versions: [trusty, xenial]

galaxy_tags: [python]

dependencies:
- role: naftulikay.base
2 changes: 2 additions & 0 deletions requirements.txt
@@ -0,0 +1,2 @@
ansible
git+https://github.com/naftulikay/travis-pls#egg=travis-pls
2 changes: 2 additions & 0 deletions requirements.yml
@@ -1,3 +1,5 @@
---
- src: naftulikay.vagrant-docker
name: vagrant-docker
- src: naftulikay.vagrant-python-dev
name: vagrant-python-dev
17 changes: 0 additions & 17 deletions tasks/discover/os.yml

This file was deleted.

11 changes: 10 additions & 1 deletion tasks/discover/python.yml → tasks/include/00-facts.yml
@@ -1,4 +1,12 @@
---
- name: load redhat variables
include_vars: redhat.yml
when: is_redhat_derivative

- name: load ubuntu variables
include_vars: ubuntu.yml
when: is_ubuntu_derivative

- name: get python user details
command: getent passwd {{ python_user }}
become: true
Expand Down Expand Up @@ -49,4 +57,5 @@
python_detected_version: "{{ '' if python_version_check.rc > 0 else python_version_check.stdout.strip() }}"

- name: detect whether correct version of python
set_fact: python_version_changed="{{ not python_detected_version.startswith(python_version) }}"
set_fact:
python_version_changed: "{{ not python_detected_version.startswith(python_version) }}"
6 changes: 6 additions & 0 deletions tasks/include/10-apt-refresh.yml
@@ -0,0 +1,6 @@
---
- name: refresh apt cache
apt: update_cache=yes cache_valid_time=3600
when: is_ubuntu_derivative
become: true

0 comments on commit 1b928a5

Please sign in to comment.