Adjusting linode-ansible template with DNS record creation.

This commit is contained in:
Emiliano Vavassori 2024-09-07 23:45:15 +02:00
parent 4059be838d
commit 3af21b1852
4 changed files with 31 additions and 7 deletions

View File

@ -3,3 +3,17 @@ description: ${DESCRIPTION}
runtime: python
template:
description: A Pulumi deployment with Linode cloud and Python, enhanced with Ansible.
config:
name:
type: String
default: ${PROJECT}
linode:
token:
description: "Linode Token"
type: String
secret: True
cloudflare:
apiToken:
description: "CloudFlare API Token for vavassori.org"
type: String
secret: True

View File

@ -3,17 +3,20 @@
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(config.vm.name,
instance = pulumi_linode.Instance(vmname,
type=config.linode.type,
region=config.linode.region,
image=config.linode.image,
label=config.vm.name,
label=vmname,
root_pass=config.vm.root_password,
authorized_keys=config.vm.sshkeys,
opts=pulumi.ResourceOptions(
@ -21,17 +24,24 @@ instance = pulumi_linode.Instance(config.vm.name,
)
)
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 '{config.vm.name} ansible_host={ipaddr} ansible_user=root' >./inventory"
lambda ipaddr: f"echo '{vmname} ansible_host={ipaddr} ansible_user=root' >./inventory"
),
delete = "rm -f ./inventory",
opts = pulumi.ResourceOptions(depends_on = [ instance ])
)
# Try the deployment with ansible
# Applying the command
execute_ansible = command.local.Command("a-deploy",
create = f"ansible-playbook {config.vm.playbook}",

View File

@ -6,10 +6,9 @@ linode:
# Basic VM configuration
vm:
name: linode-test
root_password: cicciopasticcio
sshkeys:
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso"
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps"
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILH5q/ObtC4VhNT88gebezP/svpvCoQLoZCh4DvUn4xq syntaxerrormmm@taz"
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGdTHkPCPUhvrcGgU9M6/BaEeirStM/kBnFxsLyXyelt syntaxerrormmm@kurotsuchi"
playbook: deploy.yml

View File

@ -1,5 +1,6 @@
pulumi>=3.0.0,<4.0.0
pulumi-linode>=4.0.0,<5.0.0
pulumi-command>=0.4.1
pulumi-cloudflare>=5.37.0
pyyaml>=6.0
dotmap>=1.3.30