Skip to content

Commit

Permalink
Run ansible in a crontask on service hosts
Browse files Browse the repository at this point in the history
Because this won't work well in development (it will always look at
prod-hosts), it's easily disabled with no_ansible_pull=true in the
inventory.  Fixes #3089.
  • Loading branch information
djmitche committed Dec 14, 2014
1 parent 7b0aac6 commit e6e06da
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ utility_packages:
- bash
- screen
- vim-lite # we probably do not want to bring all the stuff

# The upstream repository from which the service host crontask should pull
ansible_git_repository: https://github.com/buildbot/buildbot-infra
3 changes: 3 additions & 0 deletions prod-hosts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Available service host variables:
# - no_ansible_pull=true -- don't install a crontask to run ansible-pull (useful for development)

[jail-servicehosts]
service[1:3].buildbot.net

Expand Down
51 changes: 51 additions & 0 deletions roles/base-servicehost/tasks/ansible-pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
- name: install ansible
pkgng:
name: ansible
state: present

- name: create service account
user:
name: "{{ service_account }}"
groups: wheel
state: present

- name: create /var/ansible
file:
path: /var/ansible
mode: 0700
owner: "{{ service_account }}"
group: wheel
state: directory

- name: install vault password
template:
src: vault-password.j2
dest: /var/ansible/.vault-password
mode: 0600
owner: "{{ service_account }}"
group: wheel

# ansible-pull expects the inventory file to exist already, even before it
# clones the repo, so we clone the repo explicitly. The repo needs to be owned
# by the service user, so it's cloned in a command rather than with the 'git'
# module
- name: clone ansible git repository
shell: "git clone {{ ansible_git_repository }} /var/ansible/repo && chown -R {{ service_account }}:wheel /var/ansible/repo"
args:
creates: /var/ansible/repo

- name: test
debug:
msg: "{{ 'absent' if no_ansible_pull|default('false')|bool else 'present' }}"

- name: install ansible-pull crontask
tags: ansible-pull
cron:
name: ansible-pull
job: "ansible-pull -C master -d /var/ansible/repo/ -m git -U {{ ansible_git_repository }} -o -s 3600 -i /var/ansible/repo/prod-hosts --vault-password-file=/var/ansible/.vault-password site.yml"
user: "{{ service_account }}"
minute: 0
state: "{{ 'present' if no_ansible_pull|default('false')|bool else 'absent' }}"

# vim:ft=yaml:nosi:noai:ts=2:sw=2
1 change: 1 addition & 0 deletions roles/base-servicehost/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
- include: users.yml
- include: ansible-pull.yml
1 change: 1 addition & 0 deletions roles/base-servicehost/templates/vault-password.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ vault_password }}

0 comments on commit e6e06da

Please sign in to comment.