-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansible_enforcement_v4.sh
executable file
·111 lines (83 loc) · 2.8 KB
/
ansible_enforcement_v4.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
103
104
105
106
107
108
109
110
111
#!/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
if { [ "$TOGGLE_CHECK" = "-h" ] || [ "$TOGGLE_CHECK" = "--help" ] || [ "$TOGGLE_CHECK" = "" ]; };
then
echo -e "\e[1;37m
-----------------------------------------------------------------------------------------------
############### THIS SCRIPT WILL RUN THE PLAYBOOK IN TWO MODES ###############
SYNTAX: [script] [options] [playbook]
OPTIONS:
-h, --help This will show you this message.
--dry_run This will NOT enforce the playbook just displays a 'dry' run
which shows the difference of the changes that would take place.
--stateful This enforces the changes specified in the playbook.
PLAYBOOK:
[playbook] Name of existing playbook in $ANSIBLE_HOME/playbooks/ directory.
-----------------------------------------------------------------------------------------------
\e[0m"
elif [ "$TOGGLE_CHECK" = "--dry_run" ];
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_NOCOWS=1 ansible-playbook $PLAYBOOK_PATH --check --diff ## >> $LOGFILE
else
echo -e "\e[1;36m
Check Failed please review ansible syntax
\e[0m" ## >> $LOGFILE
fi
elif [ "$TOGGLE_CHECK" = "--stateful" ];
then
echo -e "\e[1;32m
**************************************
**************************************
********* Running Playbook ***********
**************************************
**************************************
\e[0m"
cd $DESTINATION_DIR
ANSIBLE_NOCOWS=1 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_NOCOWS=1 ansible-playbook $PLAYBOOK_PATH ## >> $LOGFILE
else
echo -e "\e[1;31m
Check Failed please review ansible syntax
\e[0m" ## >> $LOGFILE
fi
elif [ "$TOGGLE_CHECK" != "--dry_run" ];
then
echo -e "\e[1;31m
!!!!!!!!!! Please use -h, --help to see a list of accepted arguments and options!!!!!!!!!!
\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 !!!!!!!!!!
#"