Skip to content
Snippets Groups Projects
Commit f3b74238 authored by nimrod's avatar nimrod
Browse files

- Forked from ansible-role-example.

- Added test for SNI support.
- Added OpenBSD 5.6, Debian Jessie and Ubuntu Trusty and Xenial as test
platforms.
- Add symlink to pip on OpenBSD so that the pip Ansible module works
without specifying the path to the executable.
- Install packages that add support for SSL SNI on versions older than
2.7.9.
parent b8be0e68
Branches
Tags
No related merge requests found
Example Python 2.7
####### ##########
An (empty) example Ansible role complete with working tests out of the box. For Install Python 2.7, pip and packages to enable SSL SNI support (if needed).
more information read the `blog post
<https://www.shore.co.il/blog/ansible-example-role/>`_.
Requirements Requirements
------------ ------------
......
--- ---
# defaults file for ansible-role-example # defaults file for ansible-role-python27
--- ---
# handlers file for ansible-role-example # handlers file for ansible-role-python27
...@@ -7,9 +7,18 @@ galaxy_info: ...@@ -7,9 +7,18 @@ galaxy_info:
platforms: platforms:
- name: OpenBSD - name: OpenBSD
versions: versions:
- 5.6
- 5.7
- 5.8
- 5.9 - 5.9
- 6.0
- name: Debian
versions:
- jessie
- stretch
- name: Ubuntu
versions:
- trusty
- xenial
galaxy_tags: [ ansible ] galaxy_tags: [ ansible ]
dependencies: dependencies: []
- src: https://www.shore.co.il/git/ansible-role-openbsd-bootstrap
scm: git
role: openbsd_bootstrap
...@@ -13,10 +13,18 @@ vagrant: ...@@ -13,10 +13,18 @@ vagrant:
- name: virtualbox - name: virtualbox
type: virtualbox type: virtualbox
platforms: platforms:
- name: openbsd - name: openbsd56
box: tmatilai/openbsd-5.6
- name: openbsd60
box: kaorimatz/openbsd-6.0-amd64 box: kaorimatz/openbsd-6.0-amd64
- name: trusty
box: ubuntu/trusty64
- name: xenial
box: ubuntu/xenial64
- name: jessie
box: debian/jessie64
instances: instances:
- name: ansible-role-example - name: ansible-role-python27
options: options:
append_platform_to_hostname: yes append_platform_to_hostname: yes
raw_config_args: raw_config_args:
......
--- ---
# tasks file for ansible-role-example # tasks file for ansible-role-python27
- name: Assertions - name: Assertions
assert: assert:
that: that:
- ansible_os_family == 'OpenBSD' - ansible_os_family in ['OpenBSD', 'Debian']
- ansible_distribution_release == '6.0' - ansible_distribution_release in ['5.6', '5.7', '5.8', '5.9', '6.0', 'trusty', 'xenial', 'jessie', 'stretch']
- name: APT install
when: ansible_pkg_mgr == 'apt'
apt:
name: python-pip
state: present
update_cache: yes
cache_valid_time: 3600
- name: pkg add
when: ansible_pkg_mgr == 'openbsd_pkg'
openbsd_pkg:
name: py-pip
state: present
register: python27_pkg_add_pip
- include: pip_symlink.yml
when: ansible_os_family == 'OpenBSD'
- include: sni.yml
when: ansible_python_version|version_compare('2.7.9', '<')
---
- name: Check at which path the pip executable is installed
stat:
path: /usr/local/bin/pip-2.7
register: python27_stat_pip
- name: Symlink pip
file:
path: /usr/bin/pip
src: '{{ "/usr/local/bin/pip-2.7" if python27_stat_pip.stat.exists else "/usr/local/bin/pip2.7" }}'
state: link
owner: root
group: 0
mode: 0o0755
---
- name: APT install SSL SNI pre-requisites
when: ansible_pkg_mgr == 'apt'
apt:
name: [python2.7-dev, libssl-dev, libffi-dev]
state: present
update_cache: yes
cache_valid_time: 3600
force: yes
- name: pkg add SSL SNI pre-requisites
when: ansible_pkg_mgr == 'openbsd_pkg'
openbsd_pkg:
name: py-openssl
state: present
- name: pip install SSL SNI support
with_items:
- setuptools[certs]>=28.1.0
- pip>=7
- urllib3[secure]>=1.11
- ndg-httpsclient>=0.4.0
pip:
name: '{{ item }}'
state: present
# Include again in case the pip executable has changed during the SNI tasks.
- include: pip_symlink.yml
when: ansible_os_family == 'OpenBSD'
--- ---
- hosts: ansible-role-python27-openbsd*
gather_facts: False
roles: [ansible-role-openbsd-bootstrap]
- hosts: ansible-role-python27-xenial
gather_facts: False
roles: [ansible-role-debian-bootstrap]
- hosts: all - hosts: all
gather_facts: false roles: [ansible-role-python27]
roles:
- role: ansible-role-example
import pytest
@pytest.mark.parametrize('error', ['InsecureRequestWarning',
'InsecurePlatformWarning',
'SNIMissingWarning'])
def test_sni(Command, error):
assert error not in Command('pip install nonexistant-package').stderr
--- ---
# vars file for ansible-role-example # vars file for ansible-role-python27
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment