-
Notifications
You must be signed in to change notification settings - Fork 11
/
add_app.yml
58 lines (45 loc) · 2.1 KB
/
add_app.yml
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
---
- hosts: repository
vars_prompt:
- name: "app_name"
prompt: "\n1) Repository directory name or git repo name (mandatory)\n --> Repository location is defined in 'group_vars/all/splunk_repository'\n (Example: TA-my-app or Splunk_TA-xxx)\n Your answer"
private: no
- name: "filename"
prompt: "\n3) Repository full filename (optional)\n (Example: splunk-addon-xxx-v1.2.tgz) Leave empty if you want to use git\n Your answer"
private: no
pre_tasks:
- include_vars: group_vars/all/splunk_repository
tasks:
- name: Building full file path if defined
stat: path={{splunk_repository.repository_root}}/apps/{{ app_name }}/{{ filename }}
register: fqfilename
when: filename is defined
- name: Display filename properties (filled when app is not git)
debug:
var: fqfilename.stat.path, fqfilename.stat.size
when: fqfilename is defined
- name: Check user input
fail: msg="A required value is empty or wrong ==> '{{ item }}' <===. Please restart and ensure all mandatory fields are set!"
with_items: [ app_name, filename ]
when: "(item == 'filename' and {{ item }} !='' and (fqfilename.stat.exists != true or fqfilename.stat.isreg != true or fqfilename.stat.size < 100))
or (item is not defined and item != 'filename')
or (item is defined and {{ item }} == '' and item != 'filename')"
- name: Convert to ansible friendly name
set_fact:
app_variable: "{{ app_name | regex_replace('-', '_')}}"
- name: Copy template app template
command: cp -RfT roles/apps/app.template roles/apps/{{ app_name }}
- name: Set app variables
template: src=roles/apps/{{ app_name }}/vars/main.yml.j2
dest=roles/apps/{{ app_name }}/vars/main.yml
mode=0640
- name: Remove template file
file: path=roles/apps/{{ app_name }}/vars/main.yml.j2
state=absent
- name: Find app roles
command: "ls roles/apps"
register: app_roles
- name: Create deploy_apps.yml
template: src=roles/common/templates/deploy_apps.yml.j2
dest=./deploy_apps.yml
mode=0640