-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·77 lines (60 loc) · 1.64 KB
/
script.sh
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
#!/bin/bash
if ! [ $(id -u) == 0 ]; then
echo "Need to run the script as sudo!"
exit 1
fi
#all the roles are here
roles="${@:-test_role}"
#creating the ansible directory, playbook, ansible.cfg, and inventory
mkdir -p ansible{/inventory,/roles} && cd ansible
#creating playbook, configuration and inventory files
files="main.yml ansible.cfg inventory/all"
for file in $files; do touch $file; done
cat <<EOF >> ansible.cfg
[defaults]
callback_whitelist = profile_tasks
inventory = inventory/all
stdout_callback = yaml
EOF
#Getting all the roles
for role in $roles; do
# list of directories
dirs="defaults tasks templates handlers library"
#craeting the directories and files
for dir in $dirs; do
mkdir -p "roles/$role/$dir"
#creating template file
if [[ "$dir" == 'templates' ]]; then touch "roles/$role/$dir/server.conf.j2" && continue; fi
#creating module file
if [[ "$dir" == 'library' ]]; then wget https://raw.githubusercontent.com/Vortexdude/src/main/hello.py -O roles/$role/$dir/hello.py && continue; fi
#creating taks file
if [[ "$dir" = 'tasks' ]]; then
cat <<EOF >> "roles/$role/$dir/main.yml"
- name: New hello module
hello:
name: 'hello'
new: true
register: testout
- name: output of the hello command
debug:
msg: '{{ testout }}'
EOF
continue
fi
#create rest of the file
touch "roles/$role/$dir/main.yml"
done
echo "Your role is $role is created Succesfully "
done
#Creating playbook
cat <<EOF >> main.yml
- hosts: localhost
become: true
roles:
EOF
# include role in the playbook
for role in $roles; do
cat << EOF >>main.yml
- { role: $role }
EOF
done