-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequirements.sh
154 lines (135 loc) · 4.95 KB
/
requirements.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
# Define used variables
miniforge_script=Miniforge3-Linux-x86_64.sh
miniforge_url=https://github.com/conda-forge/miniforge/releases/latest/download/$miniforge_script
miniforge_base=/opt/miniforge
miniforge_path=/opt/miniforge/miniforge3
miniforge_link=/opt/miniforge/miniforge
conda_env_python_version=3.12
ansible_vault_file=~/.vault_pass.txt
echo "===================================================================================================================="
echo "====================== Idempotent installation script for Terraform, Go and Ansible ======================"
echo "===================================================================================================================="
echo ""
# Install Terraform if not present and $1 is all
if [ "$1" == "all" ]
then
if command_output=$(terraform -version > /dev/null 2>&1)
then
echo "Terraform is already installed."
echo ""
echo "Using Terraform version:"
echo ""
terraform -version
echo ""
else
echo "Terraform is not installed."
echo ""
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update
sudo apt-get install terraform
echo "Successfully installed Terraform."
echo ""
echo "Using Terraform version:"
terraform -version
echo ""
fi
fi
# Install Go if not present and $1 is all
if [ "$1" == "all" ]
then
if command_output=$(go version > /dev/null 2>&1)
then
echo "Go is already installed."
echo ""
echo "Using Go version:"
echo ""
go version
echo ""
else
echo "Go is not installed."
echo ""
sudo apt-get update && sudo apt-get install -y golang-go
echo "Successfully installed Go."
echo ""
echo "Using Go version:"
go version
echo ""
fi
fi
# Install Ansible if not present
if command_output=$(ansible --version > /dev/null 2>&1)
then
echo "Ansible is already installed."
echo ""
echo "Using Ansible version:"
ansible --version
echo ""
else
echo "Ansible is not installed."
echo ""
# Remove present Miniforge files in /tmp
rm /tmp/Miniforge* > /dev/null 2>&1
# Check if Miniforge is installed and remove if present
if [ -d $miniforge_base ]
then
sudo rm -rf $miniforge_base
fi
echo "===================================================================================================================="
echo "======================================= Install Ansible using Miniforge ======================================="
echo "===================================================================================================================="
echo ""
wget -P /tmp $miniforge_url
sudo -s <<EOF
# Set default Python version to Python3
alternatives --set python /usr/bin/python3
# Install Ansible using Miniforge
bash /tmp/$miniforge_script -b -p $miniforge_path
source $miniforge_path/etc/profile.d/conda.sh
conda create -n ansible python=$conda_env_python_version -y
conda activate ansible
conda install -c conda-forge ansible ansible-lint molecule -y
conda deactivate
ln -s $miniforge_path $miniforge_link
EOF
sudo chown -R $USER: $miniforge_base
echo ""
echo "===================================================================================================================="
echo "============================================ Configure Ansible ============================================="
echo "===================================================================================================================="
echo ""
# Create Ansible vault password if not present
if [ ! -f $ansible_vault_file ]
then
read -sp "Enter Ansible Vault Password: "
echo ""
sudo echo $REPLY > $ansible_vault_file
sudo chown $USER: $ansible_vault_file
chmod 600 $ansible_vault_file
fi
# Configure Ansible usage
if grep -Fxq "PATH=\"\$PATH:/opt/miniforge/miniforge/envs/ansible/bin\"" ~/.bashrc
then
echo "Ansible Path for Miniforge is already set in ~/.bashrc file."
echo ""
else
echo "PATH=\"\$PATH:/opt/miniforge/miniforge/envs/ansible/bin\"" >> ~/.bashrc
source ~/.bashrc
fi
echo "Successfully installed Ansible."
echo ""
echo "Using Ansible version:"
echo ""
ansible --version
echo ""
fi
echo "===================================================================================================================="
echo "====================== Installation process for Terraform, Go and Ansible finished ======================="
echo "===================================================================================================================="
echo ""