This challenge is to automate the installation of gitlab on microsoft auzre (acloudguru azure sandbox) using Terraform and Ansible.
Prior to this, previous learners have completed the challenge. For the ease of completing this challenge, we will git clone
from (https://github.com/vysky/challenge-gitlab) and run the Terraform and Ansible Playbook from here.
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)
In your terminal:
git clone https://github.com/vysky/challenge-gitlab
cd challenge-gitlab/
From your browser:
- Login to Azure portal using the username and password generated by acloudguru's Azure Sandbox
- Copy the generated resource group name in the Azure portal.
- **Open
main.tf
file and replace thedefault
value ofvariable "rg"
with the copied resource group name. - Save the
main.tf
file
** Note: You must change the resource group to your sandbox resource before moving on to Running Terraform.
In your terminal (you should be in the challenge-gitlab
folder):
az login -u <acloudguru username>
. Then copy and paste the password from acloudguru.terraform init
terraform plan
terraform apply --auto-approve
- When completed, refresh your Azure portal. Resources should have successfully deployed and three files (
inventory
,fqdn
,password
) will be generated in the working directory.
Ensure you have sshpass
installed in your terminal.
-
For Mac users, run
ansible-playbook main.yml
. -
For Windows users, you can run the playbook in a 2 ways to
ssh
into the public ip below.
Run ansible-playbook --ask-pass main.yml
and key in the password from the password
file (which should be Qwerty123456!).
- Edit the
inventory
file. - Add in
ansible_ssh_password=Qwerty123456!
after the IP address. - Run
ansible-playbook main.yml
If ansible-playbook
is successful, a Gitlab 'root' and 'password' will be generated as one of the debug message from the playbook.
- Copy the
fqdn
(url) generated in thefqdn
file and paste it in a new browser. You should be able to see the Gitlab login page. - Log in with the username
root
, copy and paste the password from the Ansible playbook debug message.
Congratulations! You have successfullu completed the challenge.
- In terminal, type
terraform destroy --auto-approve
to destroy the resources created and files generated on local machine
Further reading from Brendan (https://github.com/vysky/challenge-gitlab)
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)