summaryrefslogtreecommitdiff
path: root/posts/2014-01-04-setting-up-cgit-with-ansible.md
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--posts/2014-01-04-setting-up-cgit-with-ansible.md (renamed from posts/2014-01-04-setting-up-cgit-with-ansible.org)112
1 files changed, 48 insertions, 64 deletions
diff --git a/posts/2014-01-04-setting-up-cgit-with-ansible.org b/posts/2014-01-04-setting-up-cgit-with-ansible.md
index 80dbfe4..edebf66 100644
--- a/posts/2014-01-04-setting-up-cgit-with-ansible.org
+++ b/posts/2014-01-04-setting-up-cgit-with-ansible.md
@@ -1,51 +1,36 @@
-I've [[/ansible-and-chef/][already write]] about
-[[http://www.ansibleworks.com/][Ansible]]. I use it to manage and
-configure my servers (most of them are VMs running on my laptop, but the
-idea is the same). One of the server is used to store my personal git
-repositories, and I wanted to use [[http://git.zx2c4.com/cgit/][cgit]]
-as the front end for the public repositories instead of the old and slow
-[[https://git.wiki.kernel.org/index.php/Gitweb][gitweb]].
+I've [already write](file:///ansible-and-chef/) about [Ansible](http://www.ansibleworks.com/). I use it to manage and configure my servers (most of them are VMs running on my laptop, but the idea is the same). One of the server is used to store my personal git repositories, and I wanted to use [cgit](http://git.zx2c4.com/cgit/) as the front end for the public repositories instead of the old and slow [gitweb](https://git.wiki.kernel.org/index.php/Gitweb).
-Since there's no package in Debian for cgit, I need to have an easy
-procedure to install it. I'll show how I do it with Ansible. This could
-be useful if you're learning about Ansible are you're looking for a
-simple use case.
+Since there's no package in Debian for cgit, I need to have an easy procedure to install it. I'll show how I do it with Ansible. This could be useful if you're learning about Ansible are you're looking for a simple use case.
-** Work directory
+Work directory
+--------------
The work directory contains a bunch of files:
-- $workdir/hosts - local inventory with all the hosts, grouped by
- categories
-- $workdir/$hostname.yml - play book for a given host (more about this
- file later)
-- $workdir/roles/git - directory containing templates, tasks and
- handlers for installing cgit
-- $workdir/vars/$hostname.yml - contains all the variable needed to
- install cgit
+- $workdir/hosts - local inventory with all the hosts, grouped by categories
+- $workdir/$hostname.yml - play book for a given host (more about this file later)
+- $workdir/roles/git - directory containing templates, tasks and handlers for installing cgit
+- $workdir/vars/$hostname.yml - contains all the variable needed to install cgit
-#+BEGIN_QUOTE
- Replace $hostname with the name of the host you want to use for cgit.
-#+END_QUOTE
+> Replace $hostname with the name of the host you want to use for cgit.
-** Handlers
+Handlers
+--------
-In my case, cgit is hosted behind Nginx, so first, we need a handler to
-restart it after changing Nginx's configuration.
+In my case, cgit is hosted behind Nginx, so first, we need a handler to restart it after changing Nginx's configuration.
-#+BEGIN_EXAMPLE
+``` example
# roles/git/handlers/main.yml
- name: restart nginx
service: name=nginx state=restarted
-#+END_EXAMPLE
+```
-** Roles
+Roles
+-----
-Now we need to define our role for cgit. The idea is to install the
-required packages to be able to build cgit, to create the directories
-where we will store our repositories, and actually build cgit.
+Now we need to define our role for cgit. The idea is to install the required packages to be able to build cgit, to create the directories where we will store our repositories, and actually build cgit.
-#+BEGIN_EXAMPLE
+``` example
# roles/git/tasks/main.yml
- name: Set the directory for public repos
file: path=/srv/git/public
@@ -125,25 +110,24 @@ where we will store our repositories, and actually build cgit.
template: src=etc_cron.hourly_git-backup.j2
dest=/etc/cron.hourly/git-backup
mode=0755
-#+END_EXAMPLE
+```
-** Templates
+Templates
+---------
-We need a bunch of templates to configure and build our tools. Let's
-start with *cgit.conf*.
+We need a bunch of templates to configure and build our tools. Let's start with **cgit.conf**.
-#+BEGIN_SRC sh
+``` bash
# roles/git/templates/cgit.conf.j2
CGIT_SCRIPT_PATH = /srv/www/{{ cgit_subdomain }}.{{ domain }}
-#+END_SRC
+```
-This file is used when we build cgit to install it to a specific
-location.
+This file is used when we build cgit to install it to a specific location.
The next template is to configure cgit.
-#+BEGIN_EXAMPLE
+``` example
# roles/git/templates/etc_cgitrc.j2
root-desc=Franck Cuny's projects
@@ -153,11 +137,11 @@ The next template is to configure cgit.
scan-path=/srv/git/public
remove-suffix=1
clone-prefix=http://git.$hostname.net
-#+END_EXAMPLE
+```
This template is to configure nginx.
-#+BEGIN_EXAMPLE
+``` example
# roles/git/templates/etc_nginx_sites-available_cgit.j2
server {
@@ -184,15 +168,14 @@ This template is to configure nginx.
error_log /var/log/nginx/{{ cgit_subdomain }}.{{ domain }}-error.log;
access_log /var/log/nginx/{{ cgit_subdomain }}.{{ domain }}-access.log;
}
-#+END_EXAMPLE
+```
-** Backing up on s3
+Backing up on s3
+----------------
-I backup all my git repositories to a bucket on s3. In order to do that,
-you'll need either a new role or to update the current one by adding the
-following instructions.
+I backup all my git repositories to a bucket on s3. In order to do that, you'll need either a new role or to update the current one by adding the following instructions.
-#+BEGIN_EXAMPLE
+``` example
- name: Install s3cmd
apt: pkg=s3cmd
@@ -206,47 +189,48 @@ following instructions.
template: src=etc_cron.hourly_git-backup.j2
dest=/etc/cron.hourly/git-backup
mode=0755
-#+END_EXAMPLE
+```
We need a template to configure our access to s3.
-#+BEGIN_EXAMPLE
+``` example
[default]
access_key = {{ aws_access_key }}
secret_key = {{ aws_secret_key }}
use_https = True
-#+END_EXAMPLE
+```
And another template for our cron job.
-#+BEGIN_SRC sh
+``` bash
#!/bin/sh
s3cmd sync -v /srv/git/ s3://$hostname-backup/git/ > /tmp/s3_backup_git.log 2>&1
-#+END_SRC
+```
-** Variables
+Variables
+---------
-I have a file named *vars/$hostname.yml* that contains the
+I have a file named **vars/$hostname.yml** that contains the
-#+BEGIN_EXAMPLE
+``` example
domain: $hostname.net
cgit_subdomain: git
aws_access_key: access-key
aws_secret_key: secret-key
-#+END_EXAMPLE
+```
-** Play time
+Play time
+---------
The content of the playbook
-#+BEGIN_EXAMPLE
+``` example
- hosts: $hostname
vars_files:
- vars/$hostname.yml
roles:
- git
-#+END_EXAMPLE
+```
-Now I can tell Ansible to run this playbook, and this will install cgit
-on my server: =ansible-playbook -i hosts lj.yml=.
+Now I can tell Ansible to run this playbook, and this will install cgit on my server: `ansible-playbook -i hosts lj.yml`.