-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansible_enforcement_v3.sh
executable file
·102 lines (79 loc) · 2.54 KB
/
ansible_enforcement_v3.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
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
#!/bin/bash
#### setting variables ####
#PLAYBOOK=$2
TOGGLE_CHECK=$1
SOURCE_DIR=/var/log/ansible
DESTINATION_DIR=/etc/ansible
LOGFILE=$SOURCE_DIR/ansible.log
PLAYBOOK_PATH=/etc/ansible/playbooks/enforcement_test.yml
#PLAYBOOK_PATH=/etc/ansible/playbooks/$PLAYBOOK.yml
if { [ "$TOGGLE_CHECK" = "-h" ] || [ "$TOGGLE_CHECK" = "--help" ]; };
then
echo -e "\e[1;37m
-----------------------------------------------------------------------------------------------
##### THIS SCRIPT WILL RUN THE PLAYBOOK IN TWO MODES ######
-h, --help This will show you this message.
--check This will NOT enforce the playbook just displays a 'dry' run
and shows the difference of the changes that would take place.
NULL Not typing any argument will enforce the playbook.
-----------------------------------------------------------------------------------------------
\e[0m"
elif [ "$TOGGLE_CHECK" = "--check" ];
then
echo -e "\e[1;32m
**************************************
**************************************
*** Running Playbook in check mode ***
**************************************
**************************************
\e[0m"
cd $DESTINATION_DIR
ansible-playbook $PLAYBOOK_PATH --syntax-check ## >> $LOGFILE
if [ $? -eq 0 ]
then
echo -e "\e[1;36m
Check completed without error running full command
\e[0m" ## >> $LOGFILE
cd $DESTINATION_DIR
ansible-playbook $PLAYBOOK_PATH $TOGGLE_CHECK --diff ## >> $LOGFILE
else
echo -e "\e[1;36m
Check Failed please review ansible syntax
\e[0m" ## >> $LOGFILE
fi
elif [ "$TOGGLE_CHECK" = "" ];
then
echo -e "\e[1;32m
**************************************
**************************************
********* Running Playbook ***********
**************************************
**************************************
\e[0m"
cd $DESTINATION_DIR
ansible-playbook $PLAYBOOK_PATH --syntax-check ## >> $LOGFILE
if [ $? -eq 0 ]
then
echo -e "\e[1;36m
Check completed without error running full command
\e[0m" ## >> $LOGFILE
cd $DESTINATION_DIR
ansible-playbook $PLAYBOOK_PATH ## >> $LOGFILE
else
echo -e "\e[1;31m
Check Failed please review ansible syntax
\e[0m" ## >> $LOGFILE
fi
elif [ "$TOGGLE_CHECK" != "--check" ];
then
echo -e "\e[1;31m
!!!!!!!!!! Please use -h, --help to see a list of accepted arguments !!!!!!!!!!
\e[0m"
fi
### --diff when changing (small) files and templates, show the differences in those files
### DIFF_CHECK=$2
#elif { [ "$TOGGLE_CHECK" != "--check" ] || [ "$TOGGLE_CHECK" != "" ]; };
# then
# echo "
#!!!!!!!!!! Please use -h, --help to see a list of accepted arguments !!!!!!!!!!
#"