Skip to content

Commit

Permalink
Compat for both Xenial and Bionic and Python 2/3
Browse files Browse the repository at this point in the history
  • Loading branch information
swalkinshaw committed Dec 3, 2018
1 parent dad4fe9 commit 2acec4a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions group_vars/all/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ntp_manage_config: true
www_root: /srv/www
ip_whitelist:
- "{{ (env == 'development') | ternary(ansible_default_ipv4.gateway, ipify_public_ip | default('')) }}"
python_version: "{{ ansible_python_version[0] }}"

# Values of raw_vars will be wrapped in `{% raw %}` to avoid templating problems if values include `{%` and `{{`.
# Will recurse dicts/lists. `*` is wildcard for one or more dict keys, list indices, or strings. Example:
Expand Down
21 changes: 17 additions & 4 deletions roles/common/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,29 @@ site_keys_by_env_pair: "[
{% endfor %}
]"

apt_packages_default:
software-properties-common: "{{ apt_package_state }}"
python-pycurl: "{{ apt_package_state }}"
_apt_packages_default:
build-essential: "{{ apt_package_state }}"
python-mysqldb: "{{ apt_package_state }}"
curl: "{{ apt_package_state }}"
git: "{{ apt_package_state }}"
dbus: "{{ apt_package_state }}"
libnss-myhostname: "{{ apt_package_state }}"

apt_packages_ubuntu:
xenial:
python-software-properties: "{{ apt_package_state }}"
bionic:
software-properties-common: "{{ apt_package_state }}"

apt_packages_python:
'2':
python-pycurl: "{{ apt_package_state }}"
python-mysqldb: "{{ apt_package_state }}"
'3':
python3-pycurl: "{{ apt_package_state }}"
python3-mysqldb: "{{ apt_package_state }}"

apt_packages_default: "{{ _apt_packages_default | combine(apt_packages_python[python_version], apt_packages_ubuntu[ansible_distribution_release]) }}"

apt_packages_custom: {}
apt_packages: "{{ apt_packages_default | combine(apt_packages_custom) }}"

Expand Down
5 changes: 3 additions & 2 deletions server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- import_playbook: variable-check.yml
vars:
playbook: server.yml
python_package: "{{ python_version == '2' | ternary('python-simplejson', 'python3-simplejson') }}"

- name: Test Connection and Determine Remote User
hosts: web:&{{ env }}
Expand All @@ -14,8 +15,8 @@
gather_facts: false
become: yes
tasks:
- name: Install Python 2.x
raw: which python || sudo apt-get update && sudo apt-get install -qq -y python-simplejson
- name: Install Python
raw: which python || sudo apt-get update && sudo apt-get install -qq -y {{ python_package }}
register: python_check
changed_when: python_check.stdout is not search('/usr/bin/python')

Expand Down

0 comments on commit 2acec4a

Please sign in to comment.