Laboratório da Codaqui para testar Terraform e Ansible
- Terraform installed
- Ansible installed
- Azure account
- Clone the repository:
git clone https://github.com/codaqui/terraform-ansible-lab.git cd terraform-ansible-lab
-
Navigate to the
terraform
directory:cd terraform
-
Initialize Terraform:
terraform init
-
Apply the Terraform configuration to create the virtual machines:
terraform apply
-
Note the public IP addresses of the virtual machines from the Terraform output.
Before running the Terraform commands, you need to declare the following variables in a terraform.tfvars
file or pass them as command-line arguments:
resource_group_name
: The name of the resource grouplocation
: The location of the resource groupvm_size
: The size of the virtual machinesadmin_username
: The admin username for the virtual machinesadmin_password
: The admin password for the virtual machinesvirtual_network_name
: The name of the virtual networksubnet_name
: The name of the subnet
Example terraform.tfvars
file:
resource_group_name = "my-resource-group"
location = "East US"
vm_size = "Standard_B1s"
admin_username = "azureuser"
admin_password = "P@ssw0rd1234"
virtual_network_name = "my-vnet"
subnet_name = "my-subnet"
-
Navigate to the
ansible
directory:cd ansible
-
Update the
hosts
file with the public IP addresses of the virtual machines.
Before running the Ansible playbook, you need to declare the following variables in a vars.yml
file or pass them as command-line arguments:
ansible_user
: The remote user for the virtual machinesansible_password
: The password for the remote user
Example vars.yml
file:
ansible_user: azureuser
ansible_password: P@ssw0rd1234
- Run the Ansible playbook to install Apache on the virtual machines:
ansible-playbook -i hosts playbook.yml --extra-vars "@vars.yml"