Skip to content

Commit

Permalink
Merge pull request #5 from ninthnails/master
Browse files Browse the repository at this point in the history
Rewrite and RedHat support
  • Loading branch information
JasonGiedymin committed Nov 30, 2015
2 parents 3ae7e5b + ffdf5fe commit 688a620
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vagrant

26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
language: python
python: "2.7"

env:
- PYTHONVERSION: 3.5.0
- PYTHONVERSION: 3.3.3
- PYTHONVERSION: 2.7.10

before_install:
- sudo apt-get update -qq
- sudo apt-get install curl -y

install:
- pip install -U ansible

# Add ansible.cfg to pick up roles path.
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"

script:
# Check the role/playbook's syntax.
- "ansible-playbook -i ci/inventory ci/playbook.yml --syntax-check"

# Run the ansible ci playbook
- "ansible-playbook -i ci/inventory ci/playbook.yml --connection=local --sudo -vvvv -e python_version=$PYTHONVERSION -e 'python_path=/usr/local/python/{{ python_version }}'"

51 changes: 51 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.ssh.forward_agent = true
config.vm.synced_folder Dir.getwd, "/home/vagrant/roles/ansible-python", nfs: true

# ubuntu 12.04 that Travis CI is using
config.vm.define 'travis', primary: true do |c|
c.vm.network "private_network", ip: "192.168.100.2"
c.vm.box = "precise-server-cloudimg-amd64-vagrant-disk1"
c.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box"
c.vm.provision "shell" do |s|
s.inline = "apt-get update -y; apt-get install python-software-properties; add-apt-repository ppa:rquillo/ansible; apt-get update -y; apt-get install ansible -y"
s.privileged = true
end
end

# ubuntu 14.04 Trusty
config.vm.define 'ubuntu', primary: true do |c|
c.vm.network "private_network", ip: "192.168.100.3"
c.vm.box = "trusty-server-cloudimg-amd64-vagrant-disk1"
c.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
c.vm.provision "shell" do |s|
s.inline = "apt-get update -y; apt-get install -y software-properties-common; apt-add-repository ppa:ansible/ansible; apt-get update -y; apt-get install -y ansible"
s.privileged = true
end
end

# centos 6:
config.vm.define 'centos' do |c|
c.vm.network "private_network", ip: "192.168.100.4"
c.vm.box = "centos65-x86_64-20140116"
c.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box"
c.vm.provision "shell" do |s|
s.inline = "yum update gmp; yum install ansible -y"
s.privileged = true
end
end

# centos 7:
config.vm.define 'centos7' do |c|
c.vm.network "private_network", ip: "192.168.100.5"
c.vm.box = "centos/7"
c.vm.provision "shell" do |s|
s.inline = "yum install -y epel-release; yum install -y ansible"
s.privileged = true
end
end

end
2 changes: 2 additions & 0 deletions ci/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[local]
localhost
16 changes: 16 additions & 0 deletions ci/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---

- name: Test Playbook
hosts: localhost
connection: local
sudo: yes

roles:
- { role: ../../ }

tasks:
- name: Verify python version
command: "{{ python_path }}/bin/python{{ python_base_version }} --version"
register: command_result
failed_when: command_result.stderr != 'Python {{ python_version }}' and command_result.stdout != 'Python {{ python_version }}'

9 changes: 9 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
python_version: '3.3.3'
python_base_version: "{{ python_version.split('.')[0:2] | join('.') }}"
python_file_tag: "Python-{{ python_version }}"
python_file_name: "{{ python_file_tag }}.tgz"
python_base_url: http://www.python.org/ftp/python
python_package_url: "{{ python_base_url }}/{{ python_version }}/{{ python_file_name }}"
python_path: /usr/local

11 changes: 11 additions & 0 deletions tasks/RedHat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Install os packages
yum: name={{ [
'"@Development tools"',
'zlib-devel',
'bzip2-devel',
'openssl-devel',
'ncurses-devel',
'sqlite-devel'
] | join(',') }} state=present

24 changes: 11 additions & 13 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
---
- include: Debian.yml
when: ansible_os_family == "Debian"

- include: RedHat.yml
when: ansible_os_family == "RedHat"

- name: Check if Python {{python_version}} is installed
shell: "{{python_path}}/bin/python{{python_version[:-2]}} --version"
register: command_result
ignore_errors: True
- name: Create folder(s)
file: path=/opt/src state=directory owner=root group=root mode=0755

- name: Download python {{python_version}}
get_url: url={{python_base_url}} dest=/tmp/{{python_file_name}}
when: "'not found' in command_result.stderr"
- name: 'Download python {{ python_version }}'
get_url: url={{ python_package_url }} dest=/opt/src/{{ python_file_name }}

- name: Unpack python {{python_version}}
command: tar -xvzf {{python_file_name}} chdir=/tmp
when: "'not found' in command_result.stderr"
- name: 'Unpack python {{ python_version }}'
command: tar -xzf {{ python_file_name }} chdir=/opt/src creates=/opt/src/{{ python_file_tag }}

- name: Compile and install python {{python_version}}
shell: ./configure --prefix={{python_path}}/ && make && make altinstall chdir=/tmp/{{python_file_tag}}
- name: 'Compile and install python {{ python_version }}'
shell: ./configure --prefix={{ python_path }}/ && make && make altinstall chdir=/opt/src/{{ python_file_tag }} creates={{ python_path }}/bin/python{{ python_base_version }}
sudo: true
when: "'not found' in command_result.stderr"
7 changes: 1 addition & 6 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
---
python_playbook_version: "0.1.0"
python_version: "3.3.3"
python_file_tag: "Python-{{python_version}}"
python_file_name: "{{python_file_tag}}.tgz"
python_base_url: "http://www.python.org/ftp/python/{{python_version}}/{{python_file_name}}"
python_path: "/usr/local"
python_playbook_version: "0.2.0"

0 comments on commit 688a620

Please sign in to comment.