summaryrefslogtreecommitdiff
path: root/ansible/roles/trove-setup/tasks/lorry-controller-setup.yml
blob: f256bc40d822d606fd865a310e7e149bcfe39516 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Depends on:
# - gitano-setup.yml
# - lighttpd.yml
---
- name: Create the TROVE_ID/local-config/lorries repository
  shell: |
         su git -c 'ssh localhost create '{{ TROVE_ID|quote|quote|quote }}'/local-config/lorries'
         creates=/home/git/repos/{{ TROVE_ID|regex_replace('(\\W)', '\\\\\\1')}}/local-config/lorries.git
- name: Create a temporary folder to copy templates
  shell: su git -c 'mktemp -d'
  register: lorry_controller_templates

- set_fact:
    UPSTREAM_TROVE_STANZA: { 
                                type: "trove",
                                trovehost: "{{ UPSTREAM_TROVE }}",
                                protocol: "{{ UPSTREAM_TROVE_PROTOCOL }}",
                                ls-interval: "4H",
                                interval: "2H",
                                prefixmap: {
                                    baserock: "baserock",
                                    delta: "delta"
                                },
                                ignore: [
                                    "baserock/lorries"
                                ],
                                tarball: "always"
                           }
  when: UPSTREAM_TROVE is defined

- name: Create the configuration files of lorry-controller using templates
  template: src=/usr/share/trove-setup/{{ item }} dest={{ lorry_controller_templates.stdout }}/{{ item }} owner=git group=git mode=0644
  with_items:
  - lorry-controller.conf
  - README.lorry-controller
- name: Create a temporary folder to copy the lorry-controller repository
  shell: su git -c 'mktemp -d'
  register: lorry_controller_repository

- name: Configure the lorry-controller
  shell: |
         su git -c 'git clone ssh://localhost/'{{ TROVE_ID|quote|quote }}'/local-config/lorries.git '{{ lorry_controller_repository.stdout|quote|quote }}'/lorries'
         su git -c 'cp '{{ lorry_controller_templates.stdout|quote|quote }}'/lorry-controller.conf '{{ lorry_controller_repository.stdout|quote|quote }}'/lorries/lorry-controller.conf'
         su git -c 'cp '{{ lorry_controller_templates.stdout|quote|quote }}'/README.lorry-controller '{{ lorry_controller_repository.stdout|quote|quote }}'/lorries/README'
         su git -c 'mkdir '{{ lorry_controller_repository.stdout|quote|quote }}'/lorries/open-source-lorries'
         su git -c 'cp /usr/share/trove-setup/open-source-lorries/README '{{ lorry_controller_repository.stdout|quote|quote }}'/lorries/open-source-lorries/README'
         su git -c 'mkdir '{{ lorry_controller_repository.stdout|quote|quote }}'/lorries/closed-source-lorries'
         su git -c 'cp /usr/share/trove-setup/closed-source-lorries/README '{{ lorry_controller_repository.stdout|quote|quote }}'/lorries/closed-source-lorries/README'
         su git -c 'cd '{{ lorry_controller_repository.stdout|quote|quote }}'/lorries; git add README lorry-controller.conf open-source-lorries/README closed-source-lorries/README; git commit -m "Initial configuration"; git push origin master'
         su git -c 'rm -rf '{{ lorry_controller_repository.stdout|quote|quote }}
         creates=/home/git/repos/{{ TROVE_ID|regex_replace('(\\W)', '\\\\\\1')}}/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 lorry -c 'crontab -l | grep -e "-c lorry-controller"'
  register: lorry_controller_cronjob
  changed_when: False
  ignore_errors: True

- name: Remove the old lorry-controller cronjob
  shell: su lorry -c '/usr/libexec/remove-lorry-controller-from-lorry-crontab'
  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
  service: name=lorry-controller-status.service enabled=yes
  register: lorry_controller_status_service
- 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
  service: name=lorry-controller-readconf.service enabled=yes
  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
  service: name=lorry-controller-ls-troves.service enabled=yes
  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-remove-ghost-jobs service
  service: name=lorry-controller-remove-ghost-jobs.service enabled=yes
  register: lorry_controller_remove_ghost_jobs_service
- name: Start lorry-controller-remove-ghost-jobs service
  service: name=lorry-controller-remove-ghost-jobs.service state=restarted
  when: lorry_controller_remove_ghost_jobs_service|changed

- name: Enable lorry-controller-remove-old-jobs service
  service: name=lorry-controller-remove-old-jobs.service enabled=yes
  register: lorry_controller_remove_old_jobs_service
- name: Start lorry-controller-remove-old-jobs service
  service: name=lorry-controller-remove-old-jobs.service state=restarted
  when: lorry_controller_remove_old_jobs_service|changed

- name: Enable lorry-controller-status timer
  service: name=lorry-controller-status.timer enabled=yes
  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
  service: name=lorry-controller-readconf.timer enabled=yes
  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
  service: name=lorry-controller-ls-troves.timer enabled=yes
  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

- name: Enable lorry-controller-remove-ghost-jobs timer
  service: name=lorry-controller-remove-ghost-jobs.timer enabled=yes
  register: lorry_controller_remove_ghost_jobs_timer
- name: Start lorry-controller-remove-ghost-jobs timer
  service: name=lorry-controller-remove-ghost-jobs.timer state=restarted
  when: lorry_controller_remove_ghost_jobs_timer|changed

- name: Enable lorry-controller-remove-old-jobs timer
  service: name=lorry-controller-remove-old-jobs.timer enabled=yes
  register: lorry_controller_remove_old_jobs_timer
- name: Start lorry-controller-remove-old-jobs timer
  service: name=lorry-controller-remove-old-jobs.timer state=restarted
  when: lorry_controller_remove_old_jobs_timer|changed