Skip to content
This repository has been archived by the owner on Sep 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2 from loliee/improvements-serverspec
Browse files Browse the repository at this point in the history
Improvements serverspec
  • Loading branch information
loliee committed Jun 28, 2015
2 parents 9d2d1f4 + 2256667 commit 408eeea
Show file tree
Hide file tree
Showing 20 changed files with 334 additions and 246 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format documentation
24 changes: 21 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,30 @@ python: "2.7"
before_install:
- sudo apt-get update -qq
- sudo apt-get remove --purge zsh
- sudo apt-get install ruby rubygems
- sudo useradd mtester -m -d /home/mtester -s /bin/bash
- sudo chgrp ```id -gn``` /home/mtester
- sudo chmod g+s /home/mtester
- sudo rm -rf /home/mtester/.zfunctions
- sudo rm -f /home/mtester/.zshrc
- umask 002
- gem install serverspec

install:
- pip install ansible
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"

script:
- ansible-playbook -i ./tests/inventory ./tests/test_install.yml --syntax-check
- ansible-playbook -i ./tests/inventory ./tests/test_zshrc.yml --connection=local --sudo
- ansible-playbook -i ./tests/inventory ./tests/test_prompt.yml --connection=local --sudo
# Check machine pre-test state.
- rspec tests/spec/before_test_spec.rb

# Check syntax
- ansible-playbook -i tests/inventory ./tests/playbooks/install.yml --syntax-check --list-tasks

# Check install
- ansible-playbook -i ./tests/inventory tests/playbooks/install.yml --connection=local --sudo
- rspec tests/spec/install_spec.rb

# Check configuration
- ansible-playbook -i ./tests/inventory tests/playbooks/configure.yml --connection=local --sudo
- rspec tests/spec/configure_spec.rb
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'serverspec'
41 changes: 41 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.2.5)
multi_json (1.11.1)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.2)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-core (3.3.1)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-its (1.2.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.3.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
serverspec (2.19.0)
multi_json
rspec (~> 3.0)
rspec-its
specinfra (~> 2.35)
specinfra (2.36.6)
net-scp
net-ssh

PLATFORMS
ruby

DEPENDENCIES
serverspec

BUNDLED WITH
1.10.5
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Ansible Role: ZSH

[![Build Status](https://travis-ci.org/loliee/ansible-zsh.svg?branch=master)](https://travis-ci.org/loliee/ansible-zsh)

Install and set up [ZSH](http://www.zsh.org/).
This role can also configure `~./zshrc` file and download and set up `prompt`.

## Requirements

- RedHat family
- Debian family
- OSX (Configuration part)

## Role Variables

### `__users__`

Unset by default, dictionary should defined like this:

```yaml
__users__:
[username]:
[option]: [value]
```
**Options**
| Option | Type | Comments |
|---------------------------|----------|---------------------------------------------------------------|
| zsh_default_shell | bool | Configure as default shell. Create `.zshrc`and `.zfunctions`. |
| zsh_prompt_install | bool | Install prompt ?, default value is `No` |
| zsh_prompt_name | string | Prompt name to load in `.zshrc`. |
| zsh_prompt_download_url | string | Prompt download url, e.g [pure](https://github.com/sindresorhus/pure) |
| zsh_prompt_additional_url | string | Prompt additional download url to put in `.zfunctions`. |
| zsh_zfunctions_directory | string | Directory of files to upload on remote `.zfunctions`. |
| zsh_zshrc_content | text | Lines to append in `~/.zshrc`. |


### Defaults

Check [defaults/main.yml](defaults/main.yml) for default values.


| Variable | Type | Comments |
|-----------------------------------|----------|-----------------------------------------------------|
| zsh_default_prompt_name | string | Default prompt_name, `mlpure`. |
| zsh_default_prompt_download_url | string | Prompt download url, [mlpure](https://github.com/loliee/mlpure) |
| zsh_default_prompt_additional_url | text | `mlpure` async lib. |Ó


## Example Playbook

The following playbook will ensure zsh is present for root user and will setup pure as prompt. This playbook will also append an alias in zshrc file.

```yaml
# ./test/playbooks/configuration.yml
- hosts: localhost
remote_user: root
vars:
__users__:
root:
zsh_prompt_install: Yes
zsh_prompt_name: pure
zsh_prompt_download_url: https://raw.githubusercontent.com/sindresorhus/pure/master/pure.zsh
zsh_prompt_additional_url: https://raw.githubusercontent.com/sindresorhus/pure/master/async.zsh
zfunctions_directory: ./files/zfunctions
zshrc_content: |
alias ls='ls -lah'
# Run
roles:
- zsh
```

## Run Tests

Require [serverspec](http://serverspec.org/).
Check [.travis.yml](.travis.yml) for details.

## Licence

MIT © [Maxime Loliée](https://github.com/loliee.com/)
86 changes: 0 additions & 86 deletions README.rst

This file was deleted.

5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

zsh_default_prompt_name: mlpure
zsh_default_prompt_download_url: https://raw.githubusercontent.com/loliee/mlpure/master/pure.zsh
zsh_default_prompt_additional_url: https://raw.githubusercontent.com/loliee/mlpure/master/async.zsh
53 changes: 0 additions & 53 deletions tasks/Config.yml

This file was deleted.

70 changes: 70 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
# Setup zshrc and prompt

- name: Set as default shell
user: name={{ item.key }} shell=/bin/zsh
with_dict: __users__ | default({})
when: >
(ansible_os_family == 'RedHat' or ansible_os_family == 'Debian') and
(item.value.has_key('zsh_default_shell') and item.value.zsh_default_shell)
- name: Generate ~.zshrc.
template:
mode=0644
src=zshrc.j2
owner={{ item.key }}
dest=~{{ item.key }}/.zshrc
with_dict: __users__ | default({})
when: (item.value.has_key('zsh_default_shell') and item.value.zsh_default_shell)

- name: Check for .zfunctions directory.
file:
state=directory
mode=0755
owner={{ item.key }}
dest=~{{ item.key }}/.zfunctions
with_dict: __users__ | default({})
when: (item.value.has_key('zsh_default_shell') and item.value.zsh_default_shell)

- name: Upload zfunctions files
copy:
src=./{{ item.value.zsh_zfunctions_directory }}/
dest=~{{ item.key }}/.zfunctions/
owner={{ item.key }}
directory_mode=yes
force=yes
mode=0755
with_dict: __users__ | default({})
when: >
item.value.has_key('zsh_zfunctions_directory')
- name: Download zsh prompt file.
get_url:
mode=0744
owner={{ item.key }}
url={{ item.value.zsh_prompt_download_url | default(zsh_default_prompt_download_url) }}
dest=~{{ item.key }}/.zfunctions/prompt_{{ item.value.zsh_prompt_name | default(zsh_default_prompt_name) }}_setup
with_dict: __users__ | default({})
when: item.value.has_key('zsh_prompt_install') and item.value.zsh_prompt_install

- name: Download zsh prompt additional file.
get_url:
mode=0744
owner={{ item.key }}
url={{ item.value.zsh_prompt_additional_url }}
dest=~{{ item.key }}/.zfunctions/{{ zsh_prompt_additional_url | basename | replace('.zsh', '') }}
with_dict: __users__ | default({})
when: >
item.value.has_key('zsh_prompt_install') and item.value.zsh_prompt_install and
item.value.has_key('zsh_prompt_additional_url') and item.value.zsh_prompt_additional_url
- name: Download zsh additional file if install default prompt.
get_url:
mode=0744
owner={{ item.key }}
url={{ zsh_default_prompt_additional_url }}
dest=~{{ item.key }}/.zfunctions/{{ zsh_default_prompt_additional_url | basename | replace('.zsh', '') }}
with_dict: __users__ | default({})
when: >
item.value.has_key('zsh_prompt_install') and item.value.zsh_prompt_install and not
item.value.has_key('zsh_prompt_name')
Loading

0 comments on commit 408eeea

Please sign in to comment.