Skip to content

Commit 3e755c1

Browse files
committed
Make our Vagrant box work with newer Ansible versions
Fixes #1178
1 parent c3fc1f4 commit 3e755c1

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

Vagrantfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
# -*- mode: ruby -*-
21
# vi: set ft=ruby :
32

4-
VAGRANTFILE_API_VERSION = "2"
3+
Vagrant.require_version ">= 1.7.0"
54

6-
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
7-
config.vm.box = "ubuntu/trusty64"
5+
Vagrant.configure(2) do |config|
6+
# TODO: https://askubuntu.com/a/854396
7+
config.vm.box = "bento/ubuntu-16.04"
8+
config.vm.boot_timeout = 1200
89
config.vm.network "forwarded_port", guest: 8000, host: 8001
910
config.vm.synced_folder ".", "/home/vagrant/pythondotorg"
10-
config.vm.network "public_network"
1111
config.vm.provider "virtualbox" do |v|
1212
v.memory = 2048
1313
end
1414
config.vm.provision "ansible" do |ansible|
1515
ansible.playbook = "provisioning/pythondotorg.yml"
1616
ansible.host_key_checking = false
1717
end
18+
config.ssh.insert_key = false
1819
config.ssh.forward_agent = true
1920
end

docs/source/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Easy setup using Vagrant
2020
# on your local shell
2121
$ google-chrome http://localhost:8001/
2222

23-
The box will be provisioned by Ansible_ 1.9.6 with Python 3.4, a virtualenv
23+
The box will be provisioned by Ansible_ 2.4.1.0 with Python 3.5, a virtualenv
2424
set up with requirements installed, and a database ready to use.
2525

2626
The box also creates a superuser with username ``cbiggles`` for you. However, you

provisioning/pythondotorg.yml

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
- name: Create a {{ project.name }} VM via Vagrant
44
hosts: all
5-
sudo: yes
6-
sudo_user: root
75
remote_user: vagrant
86
vars_files:
97
- env_vars.yml
108
tasks:
9+
# TODO: Remove this when we have a better 16.04 LTS box.
10+
- name: Make /etc/apt/sources.list useful
11+
become: yes
12+
shell: "sed -i -- 's/#deb-src/deb-src/g' /etc/apt/sources.list && sudo sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list"
13+
1114
- name: Run apt-get update
15+
become: yes
1216
apt: update_cache=yes
1317

1418
- name: Install base packages
19+
become: yes
1520
apt: name={{ item }} state=latest
1621
with_items:
1722
- build-essential
@@ -22,93 +27,90 @@
2227
- git
2328
- python3
2429
- python3-dev
25-
- python-setuptools
26-
- python-pip
30+
- python3-setuptools
31+
- python3-pip
32+
- python3-venv
2733
- ruby
34+
# - acl
2835
register: result
2936
changed_when:
30-
"'0 upgraded, 0 newly installed, 0 to remove and' not in result.stdout"
31-
32-
- name: Install base Python packages
33-
pip: name=virtualenv
37+
"result.stdout is defined and '0 upgraded, 0 newly installed, 0 to remove and' not in result.stdout"
3438

3539
- name: Install python-lxml deps
40+
become: yes
3641
apt: pkg=python-lxml state=build-dep
3742
register: result
3843
changed_when:
3944
"'0 upgraded, 0 newly installed, 0 to remove and' not in result.stdout"
4045

4146
- name: Install base Ruby packages
42-
sudo: yes
47+
become: yes
4348
gem: name=bundler user_install=no
4449

4550
- name: Install PostgreSQL
4651
apt: name={{ item }} state=installed
52+
become: yes
4753
with_items:
48-
- postgresql
49-
- postgresql-contrib
54+
- postgresql-9.5
55+
- postgresql-contrib-9.5
5056
- libpq-dev
5157
- python-psycopg2
5258

5359
- name: Ensure the PostgreSQL service is running
5460
service: name=postgresql state=started enabled=yes
5561

5662
- name: Ensure database is created
57-
sudo_user: postgres
63+
become: yes
64+
become_user: postgres
65+
vars:
66+
ansible_ssh_pipelining: true
5867
postgresql_db: name={{ database.name }}
5968
encoding='UTF-8'
6069
lc_collate='en_US.UTF-8'
6170
lc_ctype='en_US.UTF-8'
6271
state=present
6372

6473
- name: Ensure user has access to the database
65-
sudo_user: postgres
74+
become: yes
75+
become_user: postgres
76+
# TODO: https://github.com/ansible/ansible/issues/16048
77+
vars:
78+
ansible_ssh_pipelining: true
6679
postgresql_user: db={{ database.name }}
6780
name={{ database.user }}
6881
priv=ALL
6982
state=present
7083
notify: Restart PostgreSQL
7184

7285
- name: Ensure python/pythondotorg is cloned
73-
sudo: no
7486
git: repo={{ project.repo }}
7587
dest={{ project.path }}
7688
version=master
7789
accept_hostkey=yes
7890
clone=no
7991
update=no
8092

81-
# the venv module doesn't work with Debian version of Python 3.4
82-
- name: Create virtualenv
83-
sudo: no
84-
command: virtualenv -p python3.4 {{ project.virtualenv }}
85-
creates={{ project.virtualenv }}/bin/activate
86-
8793
- name: Install packages required by the Django app inside virtualenv
88-
sudo: no
8994
pip: virtualenv={{ project.virtualenv }}
95+
virtualenv_command="/usr/bin/python3 -m venv"
9096
requirements={{ project.requirements }}
9197

9298
- name: Install packages required by Gemfile
93-
sudo: no
94-
# TODO: use ``bundler: state=present`` when Ansible 2.0 released
95-
command: "bundler install"
99+
bundler: state=present
96100
args:
97101
chdir: "{{ project.path }}"
98102
register: result
99-
changed_when: "result.rc != 0 or result.stderr != ''"
103+
changed_when: "result.rc is defined and result.stderr is defined and result.rc != 0 or result.stderr != ''"
100104

101105
- name: Install database migrations
102-
sudo: no
103106
django_manage: command=migrate
104107
app_path={{ project.path }}
105108
virtualenv={{ project.virtualenv }}
106109
settings={{ django.settings }}
107110
register: result
108-
changed_when: "'No migrations to apply.' not in result.out"
111+
changed_when: "result.out is defined and 'No migrations to apply.' not in result.out"
109112

110113
- name: Create a superuser for Django admin
111-
sudo: no
112114
django_manage:
113115
command="createsuperuser --noinput --username={{ django.superuser.name }} --email={{ django.superuser.email }}"
114116
app_path={{ project.path }}
@@ -120,4 +122,5 @@
120122

121123
handlers:
122124
- name: Restart PostgreSQL
125+
become: yes
123126
service: name=postgresql state=restarted enabled=yes

0 commit comments

Comments
 (0)