Skip to content

Commit c9577b3

Browse files
authored
feat: add shell role for installing anything (#929)
* feat: add shell role for installing anything * feat: add upload capability * fix: make steps optional * chore: fix output * feat: allow to change dir * fix: change directory
1 parent f2b638a commit c9577b3

File tree

6 files changed

+158
-0
lines changed

6 files changed

+158
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# Parameters:
3+
# step_configure: A shell command snippet to execute
4+
# chdir_path: Optional, change into this directory before running the command
5+
6+
- set_fact:
7+
chdir_path: "{{ ansible_env.HOME }}"
8+
when: chdir_path is not defined
9+
10+
- set_fact:
11+
chdir_path: "{{ chdir_path }}/{{ service_id }}"
12+
when: service_id is defined
13+
14+
- block:
15+
- name: Run configure step
16+
ansible.builtin.shell: "{{step_configure}}"
17+
args:
18+
chdir: "{{ chdir_path }}"
19+
async: 600
20+
register: output
21+
become: true
22+
- fail:
23+
msg: "The command failed to install when it was expected to succeed:{{ output.stdout }}"
24+
when: output is failed
25+
when: step_configure is defined
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# Parameters:
3+
# step_onafterstart: A shell command snippet to execute
4+
# chdir_path: Optional, change into this directory before running the command
5+
6+
- set_fact:
7+
chdir_path: "{{ ansible_env.HOME }}"
8+
when: chdir_path is not defined
9+
10+
- set_fact:
11+
chdir_path: "{{ chdir_path }}/{{ service_id }}"
12+
when: service_id is defined
13+
14+
- block:
15+
- name: Run onafterstart step
16+
ansible.builtin.shell: "{{step_onafterstart}}"
17+
args:
18+
chdir: "{{ chdir_path }}"
19+
async: 600
20+
register: output
21+
become: true
22+
- fail:
23+
msg: "The command failed to install when it was expected to succeed:{{ output.stdout }}"
24+
when: output is failed
25+
when: step_onafterstart is defined
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# Parameters:
3+
# step_onbeforestart: A shell command snippet to execute
4+
# chdir_path: Optional, change into this directory before running the command
5+
6+
- set_fact:
7+
chdir_path: "{{ ansible_env.HOME }}"
8+
when: chdir_path is not defined
9+
10+
- set_fact:
11+
chdir_path: "{{ chdir_path }}/{{ service_id }}"
12+
when: service_id is defined
13+
14+
- block:
15+
- name: Run onbeforestart step
16+
ansible.builtin.shell: "{{step_onbeforestart}}"
17+
args:
18+
chdir: "{{ chdir_path }}"
19+
async: 600
20+
register: output
21+
become: true
22+
- fail:
23+
msg: "The command failed to install when it was expected to succeed:{{ output.stdout }}"
24+
when: output is failed
25+
when: step_onbeforestart is defined
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# Parameters:
3+
# step_onstart: A shell command snippet to execute
4+
# chdir_path: Optional, change into this directory before running the command
5+
6+
- set_fact:
7+
chdir_path: "{{ ansible_env.HOME }}"
8+
when: chdir_path is not defined
9+
10+
- set_fact:
11+
chdir_path: "{{ chdir_path }}/{{ service_id }}"
12+
when: service_id is defined
13+
14+
- block:
15+
- name: Run onstart step
16+
ansible.builtin.shell: "{{step_onstart}}"
17+
args:
18+
chdir: "{{ chdir_path }}"
19+
async: 600
20+
register: output
21+
become: true
22+
- fail:
23+
msg: "The command failed to install when it was expected to succeed:{{ output.stdout }}"
24+
when: output is failed
25+
when: step_onstart is defined
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# Parameters:
3+
# step_prepare: A shell command snippet to execute
4+
# chdir_path: Optional, change into this directory before running the command
5+
6+
- set_fact:
7+
chdir_path: "{{ ansible_env.HOME }}"
8+
when: chdir_path is not defined
9+
10+
- set_fact:
11+
chdir_path: "{{ chdir_path }}/{{ service_id }}"
12+
when: service_id is defined
13+
14+
- block:
15+
- name: Run prepare step
16+
ansible.builtin.shell: "{{step_prepare}}"
17+
args:
18+
chdir: "{{ chdir_path }}"
19+
async: 600
20+
register: output
21+
become: true
22+
- fail:
23+
msg: "The command failed to install when it was expected to succeed:{{ output.stdout }}"
24+
when: output is failed
25+
when: step_prepare is defined
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
# Parameters:
3+
# step_upload_file_base64: A base64 encoded file
4+
# step_upload_file_name: A filename to write the file to
5+
# chdir_path: Optional, change into this directory before running the command
6+
7+
- set_fact:
8+
chdir_path: "{{ ansible_env.HOME }}"
9+
when: chdir_path is not defined
10+
11+
- set_fact:
12+
chdir_path: "{{ chdir_path }}/{{ service_id }}"
13+
when: service_id is defined
14+
15+
- block:
16+
- fail:
17+
msg: "A step_upload_file_name is required. Create this entry in your user config file"
18+
when: step_upload_file_name is not defined
19+
- set_fact:
20+
step_upload_file_path: "{{ chdir_path }}/{{ step_upload_file_name }}"
21+
- name: decode base64 file
22+
set_fact:
23+
step_upload_file_content: "{{step_upload_file_base64 | b64decode}}"
24+
- name: Copy file to remove
25+
ansible.builtin.copy:
26+
content: "{{ step_upload_file_content }}"
27+
dest: "{{ step_upload_file_path }}"
28+
register: output
29+
become: true
30+
- fail:
31+
msg: "The command failed to upload the file {{ step_upload_file_name }} to {{ step_upload_file_path }} details:{{ output.stdout }}"
32+
when: output is failed
33+
when: step_upload_file_base64 is defined

0 commit comments

Comments
 (0)