On Tue, Jul 01, 2014 at 06:02:00PM +0100, Pedro Alvarez wrote:
diff --git a/ansible/roles/trove-setup/tasks/backups.yml
b/ansible/roles/trove-setup/tasks/backups.yml
new file mode 100644
index 0000000..a15e4c4
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/backups.yml
@@ -0,0 +1,17 @@
+# Depends on:
+# - check.yml
+---
+- name: Create the backups user if TROVE_BACKUP_KEYS is defined
+ user: name=backup comment="Backup user" shell=/bin/sh
home=/root/backup-user-home group=root uid=0 non_unique=yes
+ when: TROVE_BACKUP_KEYS is defined
+
+- name: Creates the .ssh directory to the backups user if TROVE_BACKUP_KEYS is defined
+ file: path=/root/backup-user-home/.ssh state=directory
+ when: TROVE_BACKUP_KEYS is defined
+
+- name: Copy the TROVE_BACKUP_KEYS if defined to authorized_keys of the backup user
+ shell: |
+ cat {{ TROVE_BACKUP_KEYS }} >>
/root/backup-user-home/.ssh/authorized_keys
Does ansible convert the `{{ TROVE_BACKUP_KEYS }}` interpolation into
a shell escaped string?
I'm not familiar with how Ansible/Jinja2 do interpolations, but I've
seen this be done incorrectly in other contexts.
I also saw you do an interpolation as `echo -n "{{ TROVE_ID }}"`
later, which could do unexpected things if TROVE_ID had shell special
characters in, and would do odd things indeed if TROVE_ID had a " in it.
I'd recommend not doing any quoting of your own of the {{ }}
interpolations, and instead using the quote filter.
From my limited understanding, this requires instead of using
`{{ TROVE_ID }}`, using `{{ TROVE_ID|quote }}`.
diff --git a/ansible/roles/trove-setup/tasks/gitano-admin-setup.yml
b/ansible/roles/trove-setup/tasks/gitano-admin-setup.yml
new file mode 100644
index 0000000..5c9f13a
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/gitano-admin-setup.yml
@@ -0,0 +1,39 @@
+# Depends on:
+# - gitano-setup.yml
+---
+- name: Check if the admin user is configured in gitano (This task can fail)
+ shell: su -c 'ssh git@localhost user' - git | grep '^{{ TROVE_ADMIN_USER
}}:'
Is this meant to be run as root rather than the git user?
+ register: gitano_admin_user
+ changed_when: False
+ ignore_errors: True
+# If the admin user doesn't exist
+- name: Create the admin user
+ shell: su git -c 'ssh git@localhost user add {{ TROVE_ADMIN_USER }} {{
TROVE_ADMIN_EMAIL }} {{ TROVE_ADMIN_NAME }}'
I think you can get away without prefixing the address with git@ if you're logged in
as git.
Also, I don't like the inconsistency of sometimes being `su git -c
"$command"`, but other times being `su -c "$command" - git`.
+ when: gitano_admin_user|failed
+
+- name: Check if admin user is in trove-admin group in gitano (This task can fail)
+ shell: su -c 'ssh git@localhost as {{ TROVE_ADMIN_USER }} whoami' - git | grep
'trove-admin. Trove-local administration'
+ register: gitano_admin_group
+ changed_when: False
+ ignore_errors: True
+# If the admin user is not in the trove-admin group
+- name: Add the admin user to the trove-admin group in gitano
+ shell: su -c 'ssh git@localhost group adduser trove-admin {{ TROVE_ADMIN_USER
}}' - git
+ when: gitano_admin_group|failed
+
+- name: Check if admin user has a sshkey configured in gitano (This task can fail)
+ shell: su -c 'ssh git@localhost as {{ TROVE_ADMIN_USER }} sshkey' - git 2>
/dev/stdout | grep WARNING
`2>&1` is more idiomatic shell than `2> /dev/stdout`, plus has the
advantage of working when /dev is not managed by udev.
+ register: gitano_admin_key
+ changed_when: False
+ ignore_errors: True
+# If admin user doesn't have an sshkey configured
+- name: Create /home/git/keys/ to store sshkeys
+ file: path=/home/git/keys state=directory owner=git group=git
+ when: gitano_admin_key|success
+- name: Copy the TROVE_ADMIN_SSH_PUBKEY to /home/git/keys/admin.key.pub
+ copy: src={{ TROVE_ADMIN_SSH_PUBKEY }} dest=/home/git/keys/admin.key.pub mode=0644
+ when: gitano_admin_key|success
+
+- name: Add /home/git/keys/admin.key.pub ssh key to the admin user in gitano.
+ shell: su -c 'ssh git@localhost as {{ TROVE_ADMIN_USER }} sshkey add default <
/home/git/keys/admin.key.pub' - git
+ when: gitano_admin_key|success
diff --git a/ansible/roles/trove-setup/tasks/gitano-lorry-setup.yml
b/ansible/roles/trove-setup/tasks/gitano-lorry-setup.yml
new file mode 100644
index 0000000..b2681dd
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/gitano-lorry-setup.yml
@@ -0,0 +1,18 @@
+# Depends on:
+# - gitano-setup.yml
+---
+- name: Check if lorry has a sshkey configured in gitano (This task can fail)
+ shell: su -c 'ssh git@localhost as lorry sshkey' - git 2> /dev/stdout |
grep WARNING
See the previous comment about /dev/stdout
+ register: gitano_lorry_key
+ changed_when: False
+ ignore_errors: True
+# If lorry user doesn't have an sshkey configured
+- name: Create /home/git/keys folder to store ssh keys
+ file: path=/home/git/keys state=directory owner=git group=git
+ when: gitano_lorry_key|success
+- name: Copy LORRY_SSH_PUBKEY to /home/git/keys/lorry.key.pub
+ copy: src={{ LORRY_SSH_PUBKEY }} dest=/home/git/keys/lorry.key.pub mode=0644
+ when: gitano_lorry_key|success
+- name: Add to the gitano lorry user the /home/git/keys/lorry.key.pub
+ shell: su -c 'ssh git@localhost as lorry sshkey add trove <
/home/git/keys/lorry.key.pub' - git
+ when: gitano_lorry_key|success
diff --git a/ansible/roles/trove-setup/tasks/gitano-mason-setup.yml
b/ansible/roles/trove-setup/tasks/gitano-mason-setup.yml
new file mode 100644
index 0000000..edfd873
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/gitano-mason-setup.yml
@@ -0,0 +1,16 @@
+# Depends on:
+# - gitano-setup.yml
+---
+- name: Check if mason has a sshkey configured in gitano (This task can fail)
+ shell: su -c 'ssh git@localhost as mason sshkey' - git 2> /dev/stdout |
grep WARNING
See the previous comment about /dev/stdout
+ register: gitano_mason_key
+ changed_when: False
+ ignore_errors: True
+
+# If distbuild user doesn't have an sshkey configured
+- file: path=/home/git/keys state=directory owner=git group=git
+ when: gitano_mason_key|success
+- copy: src={{ MASON_SSH_PUBKEY }} dest=/home/git/keys/worker.key.pub mode=0644
+ when: gitano_mason_key|success
+- shell: su -c 'ssh git@localhost as mason sshkey add trove <
/home/git/keys/mason.key.pub' - git
+ when: gitano_mason_key|success
diff --git a/ansible/roles/trove-setup/tasks/gitano-setup.yml
b/ansible/roles/trove-setup/tasks/gitano-setup.yml
new file mode 100644
index 0000000..a7b7903
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/gitano-setup.yml
@@ -0,0 +1,48 @@
+# Depends on:
+# - git.yml
+---
+# Before configuring Gitano, it's necessary to modify the placeholders
+# of the skeleton template of Gitano with the values of /etc/trove/trove.conf.
+# Ansible does not provide an efficient way to do this. Its template module
+# is not able to run recursively over directories, and is not able to create
+# the directories needed.
+#
+# The solution implemented consists in create the directories first and then
+# using the template module in all the files. This could be possible to
+# implement using the 'with_lines' option combinated with the 'find'
command.
+#
+# Create the directories
+- name: Create the directories needed for the Gitano skeleton.
+ file: path=/etc/{{ item }} state=directory
+ with_lines:
+ - (cd /usr/share/trove-setup && find gitano -type d)
+# Copy all the files to the right place and fill the templates whenever possible
+- name: Create the Gitano skeleton using the templates
+ template: src=/usr/share/trove-setup/{{ item }} dest=/etc/{{ item }}
+ with_lines:
+ - (cd /usr/share/trove-setup && find gitano -type f)
I'm a little annoyed there's nothing like with_lines that takes NUL
terminated output, since this would have issues if we had files with
newlines in their names, however this is just my usual pickiness about
whitespace unsafety, and we are in control of what goes into trove-setup,
so we can avoid this issue.
+
+# Configure gitano
+- name: Configure Gitano with /etc/gitano-setup.clod
+ command: |
+ /bin/su -c 'gitano-setup /etc/gitano-setup.clod' - git
+ creates=/home/git/repos/gitano-admin.git
+
+- name: Unlock the password of the git user (This task can fail)
+ shell: busybox passwd -u git
+ register: passwd_result
+ changed_when: passwd_result|success
+ ignore_errors: True
+
+# Now that /home/git/repos exists, we can enable the git-daemon service
+- name: Enable the git-daemon.service
+ shell: |
+ ln -s "/usr/lib/systemd/system/git-daemon.service" \
+ "/etc/systemd/system/multi-user.target.wants/git-daemon.service"
+ creates=/etc/systemd/system/multi-user.target.wants/git-daemon.service
+ register: git_daemon_service
+
+# Now we can start the service without rebooting the system
+- name: Restart git-daemon.service
+ service: name=git-daemon state=restarted
+ when: git_daemon_service|changed
diff --git a/ansible/roles/trove-setup/tasks/gitano-worker-setup.yml
b/ansible/roles/trove-setup/tasks/gitano-worker-setup.yml
new file mode 100644
index 0000000..a44adc0
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/gitano-worker-setup.yml
@@ -0,0 +1,18 @@
+# Depends on:
+# - gitano-setup.yml
+---
+- name: Check if worker has a sshkey configured in gitano (This task can fail)
+ shell: su -c 'ssh git@localhost as distbuild sshkey' - git 2> /dev/stdout |
grep WARNING
See previous comments about /dev/stdout.
+ register: gitano_worker_key
+ changed_when: False
+ ignore_errors: True
+# If distbuild user doesn't have an sshkey configured
+- name: Create /home/git/keys/ to store ssh keys
+ file: path=/home/git/keys state=directory owner=git group=git
+ when: gitano_worker_key|success
+- name: Copy WORKER_SSH_PUBKEY to /home/git/keys/worker.key.pub
+ copy: src={{ WORKER_SSH_PUBKEY }} dest=/home/git/keys/worker.key.pub mode=0644
+ when: gitano_worker_key|success
+- name: Add /home/git/keys/worker.key.pub to the distbuild user in Gitano
+ shell: su -c 'ssh git@localhost as distbuild sshkey add trove <
/home/git/keys/worker.key.pub' - git
+ when: gitano_worker_key|success
diff --git a/ansible/roles/trove-setup/tasks/hostname.yml
b/ansible/roles/trove-setup/tasks/hostname.yml
new file mode 100644
index 0000000..513bd89
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/hostname.yml
@@ -0,0 +1,26 @@
+# Depends on:
+# - check.yml
+---
+- name: Check the /etc/hostname and compare it with HOSTNAME (This task can fail)
+ shell: if [ "$(cat /etc/hostname)" != "{{ HOSTNAME }}" ]; then
exit 1; fi
I don't understand Ansible's shell command semantics, but unless
Ansible adds extra commands at the end, couldn't this just be
`[ "$(cat /etc/hostname)" != {{ HOSTNAME|quote }} ]`?
+ register: hostname_file
+ ignore_errors: True
+ changed_when: False
+ when: HOSTNAME is defined
I take it this was to work around Ansible not having a generic way to set the hostname?
+# If /etc/hostname doesn't match with HOSTNAME
+- name: Rewrite /etc/hostname with HOSTNAME
+ shell: echo {{ HOSTNAME }} > /etc/hostname
+ when: hostname_file|failed
+
+- name: Check the actual hostname with `hostname` and compare it with HOSTNAME (This
task can fail)
+ shell: if [ "$(hostname)" != "{{ HOSTNAME }}" ]; then exit 1; fi
+ register: actual_hostname
+ ignore_errors: True
+ changed_when: False
+ when: HOSTNAME is defined
+
+# If `hostname` doesn't match with HOSTNAME
+- name: Change the hostname to HOSTNAME
+ shell: hostname "{{ HOSTNAME }}"
+ when: actual_hostname|failed
I tend to prefer `hostname -F /etc/hostname`, but I can see this
introduces a dependency on the file being corrected first.
diff --git a/ansible/roles/trove-setup/tasks/known-hosts-setup.yml
b/ansible/roles/trove-setup/tasks/known-hosts-setup.yml
new file mode 100644
index 0000000..9f91ffa
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/known-hosts-setup.yml
@@ -0,0 +1,7 @@
+# Depends on:
+# - check.yml
+---
+- name: Add localhost and UPSTREAM_TROVE to /etc/ssh/ssh_known_hosts
+ shell: |
+ /bin/sh -c "ssh-keyscan localhost {{ UPSTREAM_TROVE }} >
/etc/ssh/ssh_known_hosts"
Is there any particular reason you can't just run `ssh-keyscan localhost
{{ UPSTREAM_TROVE }}` here? Why does it need to be invoked as
`/bin/sh -c`, if you're already saying it has to be run in a shell?
+ creates=/etc/ssh/ssh_known_hosts
diff --git a/ansible/roles/trove-setup/tasks/lighttpd.yml
b/ansible/roles/trove-setup/tasks/lighttpd.yml
new file mode 100644
index 0000000..105e307
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/lighttpd.yml
@@ -0,0 +1,51 @@
+---
+- name: Create /etc/lighttpd/certs directory
+ file: path=/etc/lighttpd/certs state=directory
+- name: Create certificates for lighttpd in /etc/lighttpd/certs/lighttpd.pem
+ shell: |
+ yes '' | openssl req -new -x509 \
+ -keyout /etc/lighttpd/certs/lighttpd.pem \
+ -out /etc/lighttpd/certs/lighttpd.pem -days 36525 -nodes
+ creates=/etc/lighttpd/certs/lighttpd.pem
+ register: lighttpd_certs
+- name: Create /var/run/lighttpd for cache user
+ file: path=/var/run/lighttpd state=directory owner=cache group=cache
+ register: lighttpd_folder
+
+# Now that the lighttpd certificates and the /var/run/lighttpd exist, we can
+# enable the lighttpd-git service
+- name: Enable lighttpd-git service
+ shell: |
+ ln -s "/usr/lib/systemd/system/lighttpd-git.service" \
+ "/etc/systemd/system/multi-user.target.wants/lighttpd-git.service"
+ creates=/etc/systemd/system/multi-user.target.wants/lighttpd-git.service
+ register: lighttpd_git_service
+
+# Now we can start the service without rebooting the system
+- name: Restart the lighttpd-git service
+ service: name=lighttpd-git state=restarted
+ when: lighttpd_git_service|changed
+
+# Once the service lighttpd-git is running it's possible to do the same
+# with the following services:
+# - lighttpd-morph-cache
+# - lighttpd-lorry-controller-webapp
+- name: Enable lighttpd-morph-cache service
+ shell: |
+ ln -s "/usr/lib/systemd/system/lighttpd-morph-cache.service" \
+
"/etc/systemd/system/multi-user.target.wants/lighttpd-morph-cache.service"
+
creates=/etc/systemd/system/multi-user.target.wants/lighttpd-morph-cache.service
+ register: lighttpd_morph_cache_service
+- name: Restart the lighttpd-morph-cache service
+ service: name=lighttpd-morph-cache state=restarted
+ when: lighttpd_morph_cache_service|changed
+
+- name: Enable the lighttpd-lorry-controller-webapp service
+ shell: |
+ ln -s
"/usr/lib/systemd/system/lighttpd-lorry-controller-webapp.service" \
+
"/etc/systemd/system/multi-user.target.wants/lighttpd-lorry-controller-webapp.service"
+
creates=/etc/systemd/system/multi-user.target.wants/lighttpd-lorry-controller-webapp.service
+ register: lighttpd_lorry_controller_webapp_service
+- name: Restart the lighttpd-lorry-controller-webapp service
+ service: name=lighttpd-lorry-controller-webapp state=restarted
+ when: lighttpd_lorry_controller_webapp_service|changed
diff --git
a/ansible/roles/trove-setup/tasks/lorry-controller-setup.yml
b/ansible/roles/trove-setup/tasks/lorry-controller-setup.yml
new file mode 100644
index 0000000..0e179d1
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/lorry-controller-setup.yml
@@ -0,0 +1,104 @@
+# Depends on:
+# - gitano-setup.yml
+# - lighttpd.yml
+---
+- name: Create the TROVE_ID/local-config/lorries repository
+ command: |
+ /bin/su -c "ssh localhost create {{ TROVE_ID
}}/local-config/lorries" - git
+ creates=/home/git/repos/{{ TROVE_ID }}/local-config/lorries.git
+- name: Create a temporary folder to copy templates
+ file: path=/tmp/lorries-tmp state=directory
I don't like tempdirs with fixed names, could you get it to use `mktemp
-d`, or does it have some built-in commands for making a tempdir?
+- name: Create the configuration files of lorry-controller using
templates
+ template: src=/usr/share/trove-setup/{{ item }} dest=/tmp/lorries-tmp/{{ item }}
+ with_items:
+ - lorry-controller.conf
+ - README.lorry-controller
+- name: Configure the lorry-controller
+ shell: |
+ su -c "git clone ssh://localhost/{{ TROVE_ID }}/local-config/lorries.git
/tmp/lorries" - git
See previous comment about tempdirs with fixed names.
+ su -c "cp /tmp/lorries-tmp/lorry-controller.conf
/tmp/lorries/lorry-controller.conf" - git
+ su -c "cp /tmp/lorries-tmp/README.lorry-controller
/tmp/lorries/README" - git
+ su -c "mkdir /tmp/lorries/open-source-lorries" - git
+ su -c "cp /usr/share/trove-setup/open-source-lorries/README
/tmp/lorries/open-source-lorries/README" - git
+ su -c "mkdir /tmp/lorries/closed-source-lorries" - git
+ su -c "cp /usr/share/trove-setup/closed-source-lorries/README
/tmp/lorries/closed-source-lorries/README" - git
+ su -c "cd /tmp/lorries; git add README lorry-controller.conf
open-source-lorries/README closed-source-lorries/README; git commit -m 'Initial
configuration'; git push origin master" - git
+ su -c "rm -rf /tmp/lorries" - git
+ creates=/home/git/repos/{{ TROVE_ID
}}/local-config/lorries.git/refs/heads/master
+
+# Migration: Remove the old lorry-controller cronjob if exists
+- name: Look for lorry-controller old cronjob (This task can fail)
+ shell: su -c 'crontab -l | grep -e "-c lorry-controller"' - lorry
+ register: lorry_controller_cronjob
+ changed_when: False
+ ignore_errors: True
+
+- name: Remove the old lorry-controller cronjob
+ shell: su -c '/usr/libexec/remove-lorry-controller-from-lorry-crontab' -
lorry
+ when: lorry_controller_cronjob|success
+
+
+# Now that the lorry-controller is configured we can enable the following
+# services and timers, and also start them
+# - lorry-controller-status
+# - lorry-controller-readconf
+# - lorry-controller-ls-troves
+- name: Enable lorry-controller-status service
+ shell: |
+ ln -s "/usr/lib/systemd/system/lorry-controller-status.service" \
+
"/etc/systemd/system/multi-user.target.wants/lorry-controller-status.service"
+
creates=/etc/systemd/system/multi-user.target.wants/lorry-controller-status.service
+ register: lorry_controller_status_service
Is there anything to disable these services when their config is
incorrect, or am I misunderstanding what this is for?
+- name: Start lorry-controller-status service
+ service: name=lorry-controller-status.service state=restarted
+ when: lorry_controller_status_service|changed
+
+- name: Enable lorry-controller-readconf service
+ shell: |
+ ln -s "/usr/lib/systemd/system/lorry-controller-readconf.service" \
+
"/etc/systemd/system/multi-user.target.wants/lorry-controller-readconf.service"
+
creates=/etc/systemd/system/multi-user.target.wants/lorry-controller-readconf.service
+ register: lorry_controller_readconf_service
+- name: Start lorry-controller-readconf service
+ service: name=lorry-controller-readconf.service state=restarted
+ when: lorry_controller_readconf_service|changed
+
+- name: Enable lorry-controller-ls-troves service
+ shell: |
+ ln -s "/usr/lib/systemd/system/lorry-controller-ls-troves.service" \
+
"/etc/systemd/system/multi-user.target.wants/lorry-controller-ls-troves.service"
+
creates=/etc/systemd/system/multi-user.target.wants/lorry-controller-ls-troves.service
+ register: lorry_controller_ls_troves_service
+- name: Start lorry-controller-ls-troves service
+ service: name=lorry-controller-ls-troves.service state=restarted
+ when: lorry_controller_ls_troves_service|changed
+
+- name: Enable lorry-controller-status timer
+ shell: |
+ ln -s "/usr/lib/systemd/system/lorry-controller-status.timer" \
+
"/etc/systemd/system/multi-user.target.wants/lorry-controller-status.timer"
+
creates=/etc/systemd/system/multi-user.target.wants/lorry-controller-status.timer
+ register: lorry_controller_status_timer
+- name: Start lorry-controller-status timer
+ service: name=lorry-controller-status.timer state=restarted
+ when: lorry_controller_status_timer|changed
+
+- name: Enable lorry-controller-readconf timer
+ shell: |
+ ln -s "/usr/lib/systemd/system/lorry-controller-readconf.timer" \
+
"/etc/systemd/system/multi-user.target.wants/lorry-controller-readconf.timer"
+
creates=/etc/systemd/system/multi-user.target.wants/lorry-controller-readconf.timer
+ register: lorry_controller_readconf_timer
+- name: Start lorry-controller-readconf timer
+ service: name=lorry-controller-readconf.timer state=restarted
+ when: lorry_controller_readconf_timer|changed
+
+- name: Enable lorry-controller-ls-troves timer
+ shell: |
+ ln -s "/usr/lib/systemd/system/lorry-controller-ls-troves.timer" \
+
"/etc/systemd/system/multi-user.target.wants/lorry-controller-ls-troves.timer"
+
creates=/etc/systemd/system/multi-user.target.wants/lorry-controller-ls-troves.timer
+ register: lorry_controller_ls_troves_timer
+- name: Start lorry-controller-ls-troves timer
+ service: name=lorry-controller-ls-troves.timer state=restarted
+ when: lorry_controller_ls_troves_timer|changed
diff --git a/ansible/roles/trove-setup/tasks/cache-setup.yml
b/ansible/roles/trove-setup/tasks/cache-setup.yml
new file mode 100644
index 0000000..ea6ffd7
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/cache-setup.yml
@@ -0,0 +1,12 @@
+# Depends on:
+# - users.yml
+---
+- name: Create artifacts and ccache folder for the cache user
+ file: path=/home/cache/{{ item }} state=directory owner=cache group=cache
+ with_items:
+ - artifacts
+ - ccache
+- name: Create /etc/exports.cache
+ shell: |
+ echo '/home/cache/ccache
*(rw,all_squash,no_subtree_check,anonuid=1002,anongid=1002)' > /etc/exports.cache
+ creates=/etc/exports.cache
diff --git a/ansible/roles/trove-setup/tasks/nfs-setup.yml
b/ansible/roles/trove-setup/tasks/nfs-setup.yml
new file mode 100644
index 0000000..2e125dc
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/nfs-setup.yml
@@ -0,0 +1,7 @@
+# Depends on:
+# - cache-setup.yml
+---
+- name: Configure nfs exports
+ shell: |
+ cat /etc/exports.cache >/etc/exports
+ creates=/etc/exports
I think it may be possible to use the /etc/exports.d directory, instead
of combining multiple files to create /etc/exports.
diff --git a/ansible/roles/trove-setup/tasks/releases.yml
b/ansible/roles/trove-setup/tasks/releases.yml
new file mode 100644
index 0000000..322a46a
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/releases.yml
@@ -0,0 +1,26 @@
+# Depends on:
+# - site-groups.yml
+---
+- name: Create the releases repository
+ shell: |
+ su -c 'ssh localhost create {{ TROVE_ID }}/site/releases' - git
+ creates=/home/git/repos/{{ TROVE_ID }}/site/releases.git
+
+- name: Create temporary folder to copy templates
+ file: path=/tmp/releases-tmp/ state=directory
See previous comments about tempdirs with fixed names.
diff --git a/ansible/roles/trove-setup/tasks/users.yml
b/ansible/roles/trove-setup/tasks/users.yml
new file mode 100644
index 0000000..65e7755
--- /dev/null
+++ b/ansible/roles/trove-setup/tasks/users.yml
@@ -0,0 +1,38 @@
+# Depends on:
+# - check.yml
+---
+- name: Create the lorry user without generating sshkeys.
+ user: name=lorry comment="Trove lorry service" shell=/bin/bash
+- name: Create the /home/lorry/.ssh folder
+ file: path=/home/lorry/.ssh state=directory owner=lorry group=lorry mode=0700
+
+- name: Create users (git, cache, mason) and ssh keys for them.
+ user: name={{ item }} comment="Trove {{ item }} service" shell=/bin/bash
generate_ssh_key=yes
+ with_items:
+ - git
+ - cache
+ - mason
+- name: Create known_hosts for all the users
+ shell: |
+ cat /etc/ssh/ssh_host_*_key.pub | cut -d\ -f1,2 | \
+ sed -e's/^/{{ TROVE_HOSTNAME }},localhost /' > \
I don't think Ansible has any built-in filters that would let us
interpolate values into a sed expression safely.
+ /home/{{ item }}/.ssh/known_hosts
+ chown {{ item }}:{{ item }} /home/{{ item }}/.ssh/known_hosts
+ chmod 600 /home/{{ item }}/.ssh/known_hosts
+ creates=/home/{{ item }}/.ssh/known_hosts
+ with_items:
+ - git
+ - cache
+ - mason
+ - lorry
+
+- name: Copy the lorry ssh private key
+ copy: |
+ src={{ LORRY_SSH_KEY }}
+ dest=/home/lorry/.ssh/id_rsa
+ owner=lorry group=lorry mode=600
+- name: Copy the lorry ssh public key
+ copy: |
+ src={{ LORRY_SSH_PUBKEY }}
+ dest=/home/lorry/.ssh/id_rsa.pub
+ owner=lorry group=lorry mode=644
diff --git a/ansible/trove-setup.yml b/ansible/trove-setup.yml
new file mode 100644
index 0000000..0ab7f0e
--- /dev/null
+++ b/ansible/trove-setup.yml
@@ -0,0 +1,6 @@
+---
+- hosts: localhost
+ vars_files:
+ - "/etc/trove/trove.conf"
+ roles:
+ - trove-setup