Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EHER committed Apr 19, 2014
0 parents commit 39c206d
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# git
Ansible role to create bare git repositories with hooks.

## variables
- eher_git_path - Path to where the git repository will be created
- eher_git_hook_post_receive - Command to be executed at post-receive hook
- eher_git_hook_pre_receive - Command to be executed at pre-receive hook

## how it works?
You cand use the role as you want. The basic use is add to your site.yml and set some required variables.
```yml
---
roles:
- role: git
eher_git_path: /home/git/queroservoluntario.git
eher_git_hook_post_receive: "make deploy"
```
Before run the role, make sure that you have your keys into files/authorized_keys. That keys are used to allow git connection.
```bash
cat ~/.ssh/id_rsa.pub >> files/authorized_keys
```

After run the role, you should have your own git repository with hook. Then you can add as a remote server.
```bash
git remote add production git@myserver:querservoluntario.git
```

Push the code and watch the hook output.
```bash
git push production master
```

That will push your master branch to server and then trigger the post-receive hook. The command "make deploy" will run. Your "make deploy" can do wharever you want, as install dependencies, run tests, update database, copy the project to web directory, etc.
21 changes: 21 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: ensure git is installed
action: apt pkg=git

- name: ensure git user exists
action: user name=git shell=/usr/bin/git-shell home=/home/git generate_ssh_key=yes

- name: ensure authorized_keys exists
action: copy src=files/authorized_keys dest=/home/git/.ssh/authorized_keys owner=git mode=0600

- name: ensure repository directories exists
action: file path={{ eher_git_path }} owner=git group=git mode=0775 state=directory

- name: create repositories
action: command chdir={{ eher_git_path }} creates={{ eher_git_path }}/HEAD git init --bare

- name: ensure repositories permisions
action: command chdir={{ eher_git_path }} chown git.git -R .

- name: ensure post-receive hooks exists
action: template src=hooks/post-receive.j2 dest={{ eher_git_path }}/hooks/post-receive owner=git mode=0755
3 changes: 3 additions & 0 deletions templates/hooks/post-receive.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
# post-receive hook
{{ eher_git_hook_post_receive|default("") }}
3 changes: 3 additions & 0 deletions templates/hooks/pre-receive.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
# pre-receive hook
{{ eher_git_hook_pre_receive|default("") }}
5 changes: 5 additions & 0 deletions templates/hooks/update.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
# update hook
{% if item.hook_update %}
{{ item.hook_update }}
{% endif %}

0 comments on commit 39c206d

Please sign in to comment.