Configure Windows VM created by VMSS through Bastion Host

Viewed 275

I have created my infrastructure through Terraform, the relevant (Azure) resources are

  • Application Gateway
  • VMSS (Virtual Machine Scale Set)
  • Windows VMs => Created/Destroyed by VMSS (Windows VM are in private subnet, and HTTPS access is through Application Gateway)
  • Ubuntu based Bastion Host (for RDP and ansible configuration)

So far I am able to configure one of my windows VM through Ansible using psrp protocol, but that was only possible because I knew the private IPV4 of my VM (added the private IP to host file of bastion vm). How can I do it without knowing the IP address(es)?

My other question is how will the Ansible know a new VM has been created and it needs to be configured?

Edit
If you think this is not the best approach, please guide me on how to do it properly? Should I use Packer with custom image? OR is there any other option? The main configuration I want to do is enable IIS and install a few programs like GIT.

Thank you.

1 Answers

The best way IMO is to use a dynamic inventory. Although the doc examples are detailed for clobber and EC2, you will find more info on the included scripts with examples for Azure.

Once you have your dynamic inventory in place, you can refresh it with meta: refresh_inventory whenever you need to.

Related