diff --git a/README.rst b/README.rst index 06fb1d664e0ac8ddbe0ea61703cdc273cea719e6..dc0b8932f305feed39e3bf58f7b54d5cb732c5db 100644 --- a/README.rst +++ b/README.rst @@ -1,9 +1,7 @@ -Example -####### +Python 2.7 +########## -An (empty) example Ansible role complete with working tests out of the box. For -more information read the `blog post -<https://www.shore.co.il/blog/ansible-example-role/>`_. +Install Python 2.7, pip and packages to enable SSL SNI support (if needed). Requirements ------------ diff --git a/defaults/main.yml b/defaults/main.yml index 25ca86f325b131ae189e74bc108bcc2bc403501e..ec3426242253f9728c153006a792032892bdecfc 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,2 @@ --- -# defaults file for ansible-role-example +# defaults file for ansible-role-python27 diff --git a/handlers/main.yml b/handlers/main.yml index 1d74a03c15eb4a405872128a9f81f91ecf354f2e..6c671a62bd2aa6fb2663712f250fe5c5e2ed8551 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,2 @@ --- -# handlers file for ansible-role-example +# handlers file for ansible-role-python27 diff --git a/meta/main.yml b/meta/main.yml index ba13102a5ee2ece7ee94ea04fd48ff2945b6f7f7..b816f20a4e3e25409dae8ecc3dcc21b4c730730e 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -7,9 +7,18 @@ galaxy_info: platforms: - name: OpenBSD versions: + - 5.6 + - 5.7 + - 5.8 - 5.9 + - 6.0 + - name: Debian + versions: + - jessie + - stretch + - name: Ubuntu + versions: + - trusty + - xenial galaxy_tags: [ ansible ] -dependencies: - - src: https://www.shore.co.il/git/ansible-role-openbsd-bootstrap - scm: git - role: openbsd_bootstrap +dependencies: [] diff --git a/molecule.yml b/molecule.yml index a62eaa4d8d288b4fcf7f6222a439687f674994f9..cc6f67e40bbf7ec6eda8e294e496a98522d511b3 100644 --- a/molecule.yml +++ b/molecule.yml @@ -13,10 +13,18 @@ vagrant: - name: virtualbox type: virtualbox platforms: - - name: openbsd + - name: openbsd56 + box: tmatilai/openbsd-5.6 + - name: openbsd60 box: kaorimatz/openbsd-6.0-amd64 + - name: trusty + box: ubuntu/trusty64 + - name: xenial + box: ubuntu/xenial64 + - name: jessie + box: debian/jessie64 instances: - - name: ansible-role-example + - name: ansible-role-python27 options: append_platform_to_hostname: yes raw_config_args: diff --git a/tasks/main.yml b/tasks/main.yml index d519bebeb40afd7912d654313c40ef6f5775c75a..33764197c0e34339563ab565afdc32d7dffeb539 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,8 +1,29 @@ --- -# tasks file for ansible-role-example +# tasks file for ansible-role-python27 - name: Assertions assert: that: - - ansible_os_family == 'OpenBSD' - - ansible_distribution_release == '6.0' + - ansible_os_family in ['OpenBSD', 'Debian'] + - 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', '<') diff --git a/tasks/pip_symlink.yml b/tasks/pip_symlink.yml new file mode 100644 index 0000000000000000000000000000000000000000..74aad8a9a183022ab09b32f8b5d8fd8095faff76 --- /dev/null +++ b/tasks/pip_symlink.yml @@ -0,0 +1,14 @@ +--- +- 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 diff --git a/tasks/sni.yml b/tasks/sni.yml new file mode 100644 index 0000000000000000000000000000000000000000..880c34ad83dc2f9a64888542699ca48bfca50874 --- /dev/null +++ b/tasks/sni.yml @@ -0,0 +1,29 @@ +--- +- 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' diff --git a/tests/playbook.yml b/tests/playbook.yml index e739a2b8827a164702a059f09277dd60fa516e36..ff1e51594503565984567aec58e2b7accb4f5fc4 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,5 +1,11 @@ --- +- 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 - gather_facts: false - roles: - - role: ansible-role-example + roles: [ansible-role-python27] diff --git a/tests/test_sni.py b/tests/test_sni.py new file mode 100644 index 0000000000000000000000000000000000000000..3f90cb27c55b394c117013b851f7394c3bafa025 --- /dev/null +++ b/tests/test_sni.py @@ -0,0 +1,8 @@ +import pytest + + +@pytest.mark.parametrize('error', ['InsecureRequestWarning', + 'InsecurePlatformWarning', + 'SNIMissingWarning']) +def test_sni(Command, error): + assert error not in Command('pip install nonexistant-package').stderr diff --git a/vars/main.yml b/vars/main.yml index 241750308ae0dc5fd6fc0d21108c47746696d808..5bbce1b50bc3052adecf785cfdfb1bf43f1fad34 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ --- -# vars file for ansible-role-example +# vars file for ansible-role-python27