this challenge is to automate the installation of gitlab on microsoft auzre (acloudguru azure sandbox) using terraform and ansible
ensure you have the following prepared and installed on your machine
- python
- az cli
- terraform
- ansible
- username and password provided by acloudguru azure sandbox (or your own azure account)
- you can either
git clone
or download the code as zip file and extract it to a directory on your machine
- login to azure portal using the username and password generated by acloudgure azure sandbox
- copy the generated resource group name in azure portal
- open
main.tf
file and replace thedefault
value ofvariable "rg"
with the copied resource group name - save the
main.tf
file
- open a terminal on your machine and navigate to the code directory
- type
az logout
to logout of any previous az sessions - type
az login -u <username>
to login to az using the generated username - enter the generated password when prompted
- begin the initialization of terraform using
terraform init
- (optional) plan terraform using
terraform plan
- apply terraform using
terraform apply --auto-approve
and wait for it to complete - when completed, resources will be deployed in azure portal and three files (inventory, fqdn, password) will be generated in the working directory for use in ansible
note
while terraform will report the deployment is completed, the resources are still being spun up in the background in azure and will not be ready straight away, thus it is recommended to wait for around 10 mins before proceeding to the next step
- ensure you are still in the same directory in the terminal
- type
ansible-playbook main.yml
to start the process - when completed, you should be able to access the gitlab login page using the fqdn (url) generated in the
fqdn
file
- in terminal, type
terraform destroy --auto-approve
to destroy the resources created and files generated on local machine
to install gitlab onto a vm, we are required to use the image provided by gitlab
in azure portal, we only need to do a search to find the gitlab image and use it to create the vm. however we are required to provide publisher
, offer
and sku
of the image to automate and create the vm in terraform
there are multiple methods to find the required parameters of the gitlab image (or other images by other publishers)
this fantastic article guide you on how to find publisher
, offer
and sku
through arm (azure resource manager) template and az powershell
this az vm image document by microsoft lists the commands to find publisher
, offer
, sku
and more
example instructions for az cli to find the sku of gitlab by first finding the publisher
, then offer
, and finally sku
- ensure you are login to az in terminal using
az login -u <username>
and enter the password when prompted - type
az vm image list-publishers --location eastus > publisher.txt
in terminal to output a txt file with a list publishers in eastus - open the publisher txt file and search for
gitlab
(there may be multiple results) and note down thename
value (as of 17 Mar 2022,gitlabinc1586447921813
is the correct publisher for the image we need to use) - type
az vm image list-offers --location eastus --publisher gitlabinc1586447921813 > offer.txt
in terminal to output a txt file with a list of offers bygitlabinc1586447921813
- open the offer txt file and note down the
name
value (it should begitlabee
) - type
az vm image list-skus --location eastus --offer gitlabee --publisher gitlabinc1586447921813 > sku.txt
in terminal to output a txt file with a list of skus - open the sku txt file and note down the
name
value (it should bedefault
) - add the
publisher
,offer
andsku
we found above to the terraform file to automate the creation of vm using the gitlab image
working in integrating both terraform script and ansible script so the automation is seemless (code is already present in the main.tf
file)
currently there is an issue failed to connect to the host via ssh: shared connection to <ip address> closed.
if we run ansible playbook right after terraform has deployed the resources
i believe it is due to the vm closing the ssh connection as one of the ansible tasks is to wait and check for bitnami credential