2024-04-19 01:27:05 +02:00
|
|
|
"""A Linode Python Pulumi program"""
|
|
|
|
|
|
|
|
import pulumi
|
|
|
|
import pulumi_linode
|
|
|
|
import pulumi_command as command
|
2024-09-07 23:45:15 +02:00
|
|
|
import pulumi_cloudflare as cloudflare
|
2024-09-21 19:53:58 +02:00
|
|
|
import additional_configs
|
|
|
|
import ansible
|
2024-04-19 01:27:05 +02:00
|
|
|
|
2024-09-21 19:53:58 +02:00
|
|
|
config = pulumi.Config()
|
|
|
|
|
|
|
|
hostname = config.require("hostname")
|
|
|
|
domainname = config.require("domainname")
|
2024-09-07 23:45:15 +02:00
|
|
|
|
2024-04-19 01:27:05 +02:00
|
|
|
# Create a Linode resource (Linode Instance)
|
2024-09-08 02:39:46 +02:00
|
|
|
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"),
|
2024-09-08 02:39:46 +02:00
|
|
|
label=hostname,
|
2024-09-21 19:53:58 +02:00
|
|
|
root_pass=additional_configs.DEFAULT_ROOT_PASSWORD,
|
|
|
|
authorized_keys=additional_configs.SSH_KEYS,
|
2024-04-19 01:27:05 +02:00
|
|
|
opts=pulumi.ResourceOptions(
|
|
|
|
custom_timeouts=pulumi.CustomTimeouts(create="2m")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2024-09-08 02:39:46 +02:00
|
|
|
zone = cloudflare.get_zone(name=domainname)
|
|
|
|
dnsrecord = cloudflare.Record(hostname,
|
|
|
|
name=hostname,
|
2024-09-07 23:45:15 +02:00
|
|
|
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-04-19 01:27:05 +02:00
|
|
|
|
2024-09-21 19:53:58 +02:00
|
|
|
adeploy = ansible.AnsibleDeployment(instance, environment, config.get('playbooks'))
|
|
|
|
adeploy.create_inventory()
|
|
|
|
adeploy.run_playbooks()
|
2024-04-19 01:27:05 +02:00
|
|
|
|
|
|
|
# Export the Instance label of the instance
|
|
|
|
pulumi.export('ip_address', instance.ip_address)
|