Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best practices #2

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
dist: trusty
become: yes
become_method: sudo

language: python
python: "2.7"

env:
- ANSIBLE_VERSION=latest
- ANSIBLE_VERSION=2.0.1.0
- ANSIBLE_VERSION=2.0.0.2
- ANSIBLE_VERSION=2.0.0.1
- ANSIBLE_VERSION=2.0.0.0

branches:
only:
- master
- best-practices

matrix:
allow_failures:
# See https://github.com/ansible/ansible-modules-core/issues/1170
# https://github.com/ansible/ansible-modules-core/issues/1298
- env: ANSIBLE_VERSION=1.9.1

before_install:
- sudo apt-get update -qq

install:
# Install Ansible.
- if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install --no-binary ansible ansible; else pip install --no-binary ansible ansible==$ANSIBLE_VERSION; fi
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"
- "{ echo '- src: https://github.com/ind9-ops/java' ; echo ' version: master' ; echo ' name: java' } >> requirement.yml
- ansible-galaxy install -r requirements.yml

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

# Run the role/playbook with ansible-playbook.
- ansible-playbook -i tests/inventory tests/test.yml -vvvv

# Run the role/playbook again, checking to make sure it's idempotent.
- >
ansible-playbook -i tests/inventory tests/test.yml
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
9 changes: 9 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
gocd_common_user: go
gocd_common_group: go
gocd_common_debian_repository: https://download.go.cd/
gocd_common_configure_ssh: false
gocd_common_ssh_known_domain: github.com
gocd_common_java_versions:
- oracle-java8-installer
- oracle-java8-set-default
7 changes: 7 additions & 0 deletions files/thoughtworks-go-download.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# {{ansible_managed}}

[thoughtworks-go-download]
name=Thoughtworks Go Repository
baseurl=https://download.go.cd/
enabled=1
gpgcheck=0
6 changes: 6 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
dependencies:
- name: ind9-ops.java
src: [email protected]:ind9-ops/java.git
version: master
java_versions: "{{gocd_common_java_versions}}"
106 changes: 106 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
- name: Determine JAVA_HOME
shell: readlink -f /usr/bin/java | sed "s:bin/java::"
register: system_java_home
changed_when: false

- name: Set GOCD_COMMON_JAVA_HOME
set_fact:
gocd_common_java_home: "{{system_java_home.stdout}}"

- name: Thoughtworks go apt repository
become: yes
become_method: sudo
apt_repository:
repo: 'deb {{gocd_common_debian_repository}} /'
state: present

# Note: If the user or group exists, but under another ID, Ansible will try and change it.
- name: Add go group
become: yes
become_method: sudo
group:
name: "{{gocd_common_group}}"
state: present

- name: Add go user with home at /var/go
become: yes
become_method: sudo
user:
name: "{{gocd_common_user}}"
comment: "Go CD User"
group: "{{gocd_common_group}}"
home: /var/go
shell: /bin/bash

- name: Gos .ssh folder
file:
path: /var/go/.ssh
state: directory
group: "{{gocd_common_group}}"
owner: "{{gocd_common_user}}"
when: gocd_common_configure_ssh

- name: SSH public key
copy:
dest: /var/go/.ssh/{{GOCD_COMMON_SSH_PUBLIC_KEY | basename}}
src: "{{gocd_common_ssh_public_key}}"
group: "{{gocd_common_group}}"
mode: 0644
owner: "{{gocd_common_user}}"
when: gocd_common_configure_ssh

- name: SSH private key
copy:
dest: /var/go/.ssh/{{gocd_common_ssh_private_key | basename}}
src: "{{gocd_common_ssh_private_key}}"
group: "{{gocd_common_group}}"
mode: 0600
owner: "{{gocd_common_user}}"
when: gocd_common_configure_ssh

- name: Ensure git server is a known host
lineinfile:
dest: /var/go/.ssh/known_hosts
create: yes
state: present
line: "{{ lookup('pipe', 'ssh-keyscan -t rsa ' + gocd_common_ssh_known_domain) }}"
regexp: "^{{gocd_common_ssh_known_domain|replace('.', '\\.') }}"
group: "{{gocd_common_group}}"
mode: 0644
owner: "{{gocd_common_user}}"
when: gocd_common_configure_ssh

- name: Create log directory
become: yes
become_method: sudo
file:
path: /var/log/go-server
state: directory
owner: "{{gocd_common_user}}"
group: "{{gocd_common_group}}"

- name: Create run directory
become: yes
become_method: sudo
file:
path: /var/run/go-server
state: directory

- name: Create var/lib/go-server directory
become: yes
become_method: sudo
file:
path: /var/lib/go-server
state: directory
owner: "{{gocd_common_user}}"
group: "{{gocd_common_group}}"

- name: Create etc/go directory
become: yes
become_method: sudo
file:
path: /etc/go
state: directory
owner: "{{gocd_common_user}}"
group: "{{gocd_common_group}}"
8 changes: 8 additions & 0 deletions test_vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
gocd_common_user: go
gocd_common_group: go
gocd_common_debian_repository: https://download.go.cd/
gocd_common_configure_ssh: false
gocd_common_ssh_known_domain: github.com
gocd_common_java_versions:
- oracle-jdk7-installer
1 change: 1 addition & 0 deletions tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
8 changes: 8 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# test file for go-common
---
- hosts: localhost
connection: local
become: yes
become_method: sudo
roles:
- ../../
7 changes: 7 additions & 0 deletions tests/vagrant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# test for go-common
---
- hosts: all
remote_user: vagrant
sudo: true
roles:
- ../../