Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MattGronwald committed May 4, 2016
0 parents commit 57eb46a
Show file tree
Hide file tree
Showing 17 changed files with 420 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/tests/test.retry
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
sudo: required

env:
- distribution: ubuntu
version: 14.04
init: /sbin/init
run_opts: "--privileged=true"
playbook: test.yml

services:
- docker

before_install:
# Pull container
- 'sudo docker pull ${distribution}:${version}'
# Customize container
- 'sudo docker build --rm=true --file=tests/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests'

script:
- 'container_id=$(mktemp)'
# Run container in detached state
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"'

# Ansible syntax check.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook} --syntax-check'

# Test role.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook}'

# Test role idempotence.
- 'sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook}'

# Clean up
- 'sudo docker stop "$(cat ${container_id})"'

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Role Name
=========

Role for turning existing directories into symlinks.
Usefull for preparing capistrano style deployments,

Requirements
------------

none

Role Variables
--------------

Use `symlinks_directory_symlink_dict` to describe your symlinks as shown in the example playbook below.

Dependencies
------------

none

Example Playbook
----------------

- hosts: servers
vars:
symlinks_directory_symlink_dict:
- { directory: '/var/www/foo/releases/00000000000000', symlink: '/var/www/foo/current' }
- { directory: '/var/www/foo/shared/common', symlink: '/var/www/foo/releases/00000000000000/common' }
- { directory: '/var/www/foo/shared/media', symlink: '//var/www/foo/releases/00000000000000/media' }
- { directory: '/var/www/foo/shared/log', symlink: '/var/www/foo/releases/00000000000000/var/log' }
roles:
- { role: votum.symlinks }

License
-------

MIT

Author Information
------------------

VOTUM GmbH
3 changes: 3 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[defaults]
roles_path=../
callback_plugins=tests/callbacks
6 changes: 6 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# #dictionary for symlinks must look like this
# directory_symlink_dictionary:
# - { directory: '/home/foo', symlink: '/home/bar' }
symlinks_directory_symlink_dict: []
symlinks_move_directory: yes
2 changes: 2 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for ansible-role-symlinks
174 changes: 174 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
galaxy_info:
author: Matthias Gronwald ([email protected])
description: Role for turning existing directories into symlinks.
company: VOTUM GmbH

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: MIT

min_ansible_version: 1.9

# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If travis integration is cofigured, only notification for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:

#
# Below are all platforms currently available. Just uncomment
# the ones that apply to your role. If you don't see your
# platform on this list, let us know and we'll get it added!
#
platforms:
- name: EL
versions:
- all
# - 5
# - 6
# - 7
#- name: GenericUNIX
# versions:
# - all
# - any
#- name: Solaris
# versions:
# - all
# - 10
# - 11.0
# - 11.1
# - 11.2
# - 11.3
- name: Fedora
versions:
- all
# - 16
# - 17
# - 18
# - 19
# - 20
# - 21
# - 22
# - 23
- name: opensuse
versions:
- all
# - 12.1
# - 12.2
# - 12.3
# - 13.1
# - 13.2
#- name: IOS
# versions:
# - all
# - any
#- name: SmartOS
# versions:
# - all
# - any
#- name: eos
# versions:
# - all
# - Any
#- name: Windows
# versions:
# - all
# - 2012R2
#- name: Amazon
# versions:
# - all
# - 2013.03
# - 2013.09
#- name: GenericBSD
# versions:
# - all
# - any
#- name: Junos
# versions:
# - all
# - any
#- name: FreeBSD
# versions:
# - all
# - 10.0
# - 10.1
# - 10.2
# - 8.0
# - 8.1
# - 8.2
# - 8.3
# - 8.4
# - 9.0
# - 9.1
# - 9.1
# - 9.2
# - 9.3
- name: Ubuntu
versions:
- all
# - lucid
# - maverick
# - natty
# - oneiric
# - precise
# - quantal
# - raring
# - saucy
# - trusty
# - utopic
# - vivid
# - wily
# - xenial
- name: SLES
versions:
- all
# - 10SP3
# - 10SP4
# - 11
# - 11SP1
# - 11SP2
# - 11SP3
- name: GenericLinux
versions:
- all
# - any
#- name: NXOS
# versions:
# - all
# - any
- name: Debian
versions:
- all
# - etch
# - jessie
# - lenny
# - sid
# - squeeze
# - stretch
# - wheezy

galaxy_tags:
- symlinks
# List tags for your role here, one per line. A tag is
# a keyword that describes and categorizes the role.
# Users find roles by searching for tags. Be sure to
# remove the '[]' above if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of
# alphanumeric characters. Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line.
# Be sure to remove the '[]' above if you add dependencies
# to this list.
17 changes: 17 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Look for symlinks that exists already as directories
stat: path="{{ item.symlink }}"
register: dirs
with_items: "{{ symlinks_directory_symlink_dict }}"

- name: Move existing directories to link source location
command: "mv {{ item.item.symlink }} {{ item.item.directory }}"
when: item.stat.exists == true and item.stat.islnk == false
with_items: "{{ dirs.results }}"

- name: Create symlinks
file:
src: "{{ item.directory }}"
dest: "{{ item.symlink }}"
state: link
with_items: "{{ symlinks_directory_symlink_dict }}"
14 changes: 14 additions & 0 deletions tests/Dockerfile.ubuntu-14.04
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ubuntu:14.04
RUN apt-get update

# Install Ansible
RUN apt-get install -y software-properties-common git
RUN apt-add-repository -y ppa:ansible/ansible
RUN apt-get update
RUN apt-get install -y ansible

COPY initctl_faker .
RUN chmod +x initctl_faker && rm -fr /sbin/initctl && ln -s /initctl_faker /sbin/initctl

# Install Ansible inventory file
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
3 changes: 3 additions & 0 deletions tests/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[defaults]
roles_path=../
callback_plugins=tests/callbacks
23 changes: 23 additions & 0 deletions tests/initctl_faker
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
ALIAS_CMD="$(echo ""$0"" | sed -e 's?/sbin/??')"

case "$ALIAS_CMD" in
start|stop|restart|reload|status)
exec service $1 $ALIAS_CMD
;;
esac

case "$1" in
list )
exec service --status-all
;;
reload-configuration )
exec service $2 restart
;;
start|stop|restart|reload|status)
exec service $2 $1
;;
\?)
exit 0
;;
esac
1 change: 1 addition & 0 deletions tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
1 change: 1 addition & 0 deletions tests/test.retry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
45 changes: 45 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
- hosts: localhost
remote_user: root

vars:
symlinks_directory_symlink_dict:
- { directory: '/tmp/votum.symlinks/releases/00000000000000', symlink: '/tmp/votum.symlinks/current' }
- { directory: '/tmp/votum.symlinks/shared/common', symlink: '/tmp/votum.symlinks/releases/00000000000000/common' }
- { directory: '/tmp/votum.symlinks/shared/media', symlink: '/tmp/votum.symlinks/releases/00000000000000/media' }
- { directory: '/tmp/votum.symlinks/shared/log', symlink: '/tmp/votum.symlinks/releases/00000000000000/var/log' }
test_directories:
- /tmp/votum.symlinks/releases/00000000000000/common
- /tmp/votum.symlinks/releases/00000000000000/media
- /tmp/votum.symlinks/releases/00000000000000/var
- /tmp/votum.symlinks/shared/log

pre_tasks:
- name: create directory structure
file:
path: "{{ item }}"
state: directory
mode: 0755
with_items: "{{ test_directories }}"
ignore_errors: yes

roles:
- role_under_test

post_tasks:
- stat: path="{{ symlinks_directory_symlink_dict.0.symlink }}"
register: sym1
- fail: msg="path {{ symlinks_directory_symlink_dict.0.symlink }} doesn't exist or isn't a symlink"
when: sym1.stat.islnk is not defined or not sym1.stat.islnk
- stat: path="{{ symlinks_directory_symlink_dict.1.symlink }}"
register: sym2
- fail: msg="path {{ symlinks_directory_symlink_dict.1.symlink }} doesn't exist or isn't a symlink"
when: sym2.stat.islnk is not defined or not sym2.stat.islnk
- stat: path="{{ symlinks_directory_symlink_dict.2.symlink }}"
register: sym3
- fail: msg="path {{ symlinks_directory_symlink_dict.2.symlink }} doesn't exist or isn't a symlink"
when: sym3.stat.islnk is not defined or not sym3.stat.islnk
- stat: path="{{ symlinks_directory_symlink_dict.3.symlink }}"
register: sym4
- fail: msg="path {{ symlinks_directory_symlink_dict.3.symlink }} doesn't exist or isn't a symlink"
when: sym4.stat.islnk is not defined or not sym4.stat.islnk
1 change: 1 addition & 0 deletions tests/test_local.retry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
Loading

0 comments on commit 57eb46a

Please sign in to comment.