Skip to content

Commit

Permalink
Create main site.yml and rearrange files
Browse files Browse the repository at this point in the history
Ref #1
Ref #2
Ref #3
Ref #4
Ref #5
Ref #28
Ref #29
Ref #30
Ref #31
  • Loading branch information
rxaviers committed Apr 8, 2015
1 parent aaa7fbd commit 05545ca
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 128 deletions.
43 changes: 18 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
The goal of this project is to automate a series of deployment scripts by
using [puppet](https://puppetlabs.com/learn) language instead.
using ansible language.

A brand new Ubuntu 14.04 LTS installation will be provided.
Premise:
- Machines are provisioned with a brand new Ubuntu 14.04 LTS installation.

An agreement was made to use Ansible instead of Puppet because it does not require client installed on target machine, it only requires python which is one of the basic packets installed on clean machine.
Steps to deploy a target machine:

Steps to provision target machine:
1. Install Ansible on your local system. Follow [these instructions for
Ubuntu](http://docs.ansible.com/intro_installation.html#latest-releases-via-apt-ubuntu)
based systems:
1. Clone this repo and create a file called `hosts` in the project root
directory with the following content, where `host_name` is the target machine
name, and `host_ip` is the target machine IP address.

1. Install Ansible on your local system. Follow these instructions for Ubuntu based systems:
http://docs.ansible.com/intro_installation.html#latest-releases-via-apt-ubuntu
[webservers]
<host_name1> ansible_ssh_host=<host_ip1>
<host_name2> ansible_ssh_host=<host_ip2>
...

2. Clone this repo and create file called hosts in the project root directory with the following content:
```
test1 ansible_ssh_host=178.62.144.132
```
- where:
- test1 is ansible name for target machine
- ansible_ssh_host is the target machines IP address

You can create as many as you wish separate target machines that you can use in later steps. You can also provision one machine from those defined at a time.
3. Deploy with the following command, where `--user` sets the login user and
`--ask-pass` provides the password for such user (can be skipped if using ssh
keys).

3. With terminal, go to the root directory of the project and issue the following command:
```
ansible-playbook -i hosts playbooks/bootstrap.yml --user root --ask-pass
```
There is documentation for ansible-playbook [here](http://linux.die.net/man/1/ansible-playbook)
ansible-playbook -i hosts site.yml --user root --ask-pass

In the example above, I have used the following switches:

* --user - User on the remote machine
* --ask-password - Providing the password for the remote machine using secured interactive shell

You can skip these switches if you manage to get ssh key access to target machines.
63 changes: 63 additions & 0 deletions common/bootstrap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---

- name: Set hosts line
lineinfile:
dest=/etc/hosts
line="{{ ansible_ssh_host }} {{ inventory_hostname }}"

- name: Set hostname
hostname:
name={{ inventory_hostname }}

- name: Set timezone
lineinfile:
dest=/etc/timezone
line="America/Sao_Paulo"

- name: Update timezone
shell: dpkg-reconfigure --frontend noninteractive tzdata

- name: Turn bash completion on
lineinfile: backup=yes state=present dest='/etc/bash.bashrc'
regexp='{{ item.regexp }}' backrefs=yes line='{{ item.line }}'
with_items:
- { regexp: '^#if ! shopt -oq posix; then', line: 'if ! shopt -oq posix; then' }
- { regexp: '^# if \[ -f /usr/share/bash-completion/bash_completion \]\; then', line: ' if [ -f /usr/share/bash-completion/bash_completion ]; then' }
- { regexp: '^# . /usr/share/bash-completion/bash_completion', line: ' . /usr/share/bash-completion/bash_completion' }
- { regexp: '^# elif \[ -f /etc/bash_completion \]\; then', line: ' elif [ -f /etc/bash_completion ]; then' }
- { regexp: '^# . /etc/bash_completion', line: ' . /etc/bash_completion' }
- { regexp: '^# fi', line: ' fi' }
- { regexp: '^#fi', line: 'fi' }

- name: Create bash.bashrc.d folder
file: state=directory path=/etc/bash.bashrc.d

- name: Include bash.bashrc.d directory
lineinfile: backup=yes state=present dest=/etc/bash.bashrc
line="source /etc/bash.bashrc.d/*"

- name: Gentoo ps
copy: src=common/bootstrap/gentoo_ps dest=/etc/bash.bashrc.d/gentoops

- name: Append default editor to environment
lineinfile: backup=yes state=present dest=/etc/environment
line="EDITOR=vim"

- name: Append rails environment to environment
lineinfile: backup=yes state=present dest=/etc/environment
line="RAILS_ENV=production"

- name: File .bashrc
copy: src=common/bootstrap/root_bashrc dest=/root/.bashrc group=root owner=root mode=700

- name: Append additional file to vimrc
lineinfile: backup=yes state=present dest=/etc/vim/vimrc
line="source /etc/vim/vimrc.custom"

- copy: src=common/bootstrap/vimrc.custom dest=/etc/vim/vimrc.custom

- name: Ensure that root .ssh directory is created
file: state=directory path=/root/.ssh mode=700

- name: Save public key to authorized keys
get_url: url=https://github.com/rxaviers.keys dest=/root/.ssh/authorized_keys mode=700
File renamed without changes.
File renamed without changes.
File renamed without changes.
71 changes: 0 additions & 71 deletions playbooks/bootstrap.yml

This file was deleted.

13 changes: 0 additions & 13 deletions playbooks/deploy.yml

This file was deleted.

19 changes: 0 additions & 19 deletions playbooks/git.yml

This file was deleted.

14 changes: 14 additions & 0 deletions site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- name: apply common configuration to all nodes
hosts: all
remote_user: root

tasks:
- include: common/bootstrap.yml

- name: configure and deploy the webservers and application code
hosts: webservers
remote_user: root

tasks:
- include: web/deploy.yml
- include: web/git.yml
13 changes: 13 additions & 0 deletions web/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---

- name: Create deploy user
user: name=deploy shell=/bin/bash home=/srv

- name: Lock user deploy
shell: usermod -L deploy

- name: Create srv folder
file: path=/srv owner=deploy group=deploy state=directory

- name: Set profile for deploy user
copy: src=web/deploy/profile dest=/srv/.profile
File renamed without changes.
19 changes: 19 additions & 0 deletions web/git.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---

- name: Create git group
group: name=git state=present

- name: Create git user
user: name=git home=/srv/git group=git shell=/bin/bash

- name: Create git users .ssh folder
file: path=/srv/git/.ssh state=directory owner=git group=git mode=700

- name: Create git users authorized_keys
file: path=/srv/git/.ssh/authorized_keys state=touch owner=git group=git mode=700

- name: Set profile environment for git user
copy: src=web/git/profile dest=/srv/git/.profile owner=git group=git

- name: Install git-core package
apt: name=git-core update_cache=yes
2 changes: 2 additions & 0 deletions web/git/profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PS1='\[\033[01;33m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
alias ls="ls --color=auto"

0 comments on commit 05545ca

Please sign in to comment.