pulumi-templates/linode-ansible/__main__.py

48 lines
1.2 KiB
Python
Raw Normal View History

"""A Linode Python Pulumi program"""
import pulumi
import pulumi_linode
import pulumi_command as command
import pulumi_cloudflare as cloudflare
2024-09-21 19:53:58 +02:00
import additional_configs
import ansible
2024-09-21 19:53:58 +02:00
config = pulumi.Config()
hostname = config.require("hostname")
domainname = config.require("domainname")
# Create a Linode resource (Linode Instance)
instance = pulumi_linode.Instance(hostname,
2024-09-21 19:53:58 +02:00
type=config.require("linodeType"),
region=config.require("linodeRegion"),
image=config.require("linodeImage"),
label=hostname,
2024-09-21 19:53:58 +02:00
root_pass=additional_configs.DEFAULT_ROOT_PASSWORD,
authorized_keys=additional_configs.SSH_KEYS,
opts=pulumi.ResourceOptions(
custom_timeouts=pulumi.CustomTimeouts(create="2m")
)
)
zone = cloudflare.get_zone(name=domainname)
dnsrecord = cloudflare.Record(hostname,
name=hostname,
zone_id=zone.id,
type="A",
content=instance.ip_address,
comment=f"Pulumi-generated linode"
)
2024-09-21 19:53:58 +02:00
environment = {
'name': hostname,
'hostname': hostname + '.' + domainname,
}
2024-09-21 19:53:58 +02:00
adeploy = ansible.AnsibleDeployment(instance, environment, config.get('playbooks'))
adeploy.create_inventory()
adeploy.run_playbooks()
# Export the Instance label of the instance
pulumi.export('ip_address', instance.ip_address)