"""A Linode Python Pulumi program""" import pulumi import pulumi_linode import pulumi_command as command import pulumi_cloudflare as cloudflare import yaml from dotmap import DotMap config = DotMap(yaml.safe_load(open("input.yaml").read())) vmname = pulumi.Config("name") # Create a Linode resource (Linode Instance) instance = pulumi_linode.Instance(vmname, type=config.linode.type, region=config.linode.region, image=config.linode.image, label=vmname, root_pass=config.vm.root_password, authorized_keys=config.vm.sshkeys, opts=pulumi.ResourceOptions( custom_timeouts=pulumi.CustomTimeouts(create="2m") ) ) zone = cloudflare.get_zone(name="vavassori.org") dnsrecord = cloudflare.Record(vmname, name=vmname, zone_id=zone.id, type="A", content=instance.ip_address, comment=f"Pulumi-generated linode" ) # Creating the inventory file inventory = command.local.Command("a-inventory", create = instance.ip_address.apply( lambda ipaddr: f"echo '{vmname} ansible_host={ipaddr} ansible_user=root' >./inventory" ), delete = "rm -f ./inventory", opts = pulumi.ResourceOptions(depends_on = [ instance ]) ) # Applying the command execute_ansible = command.local.Command("a-deploy", create = f"ansible-playbook {config.vm.playbook}", delete = "rm -f ./ansible.log", opts = pulumi.ResourceOptions(depends_on = [ inventory ]) ) # Export the Instance label of the instance pulumi.export('ip_address', instance.ip_address)