From 3af21b18523a422af99593acf418718927145ed9 Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Sat, 7 Sep 2024 23:45:15 +0200 Subject: [PATCH] Adjusting linode-ansible template with DNS record creation. --- linode-ansible/Pulumi.yaml | 14 ++++++++++++++ linode-ansible/__main__.py | 20 +++++++++++++++----- linode-ansible/input.yaml | 3 +-- linode-ansible/requirements.txt | 1 + 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/linode-ansible/Pulumi.yaml b/linode-ansible/Pulumi.yaml index 750317c..a8c7b0c 100644 --- a/linode-ansible/Pulumi.yaml +++ b/linode-ansible/Pulumi.yaml @@ -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 diff --git a/linode-ansible/__main__.py b/linode-ansible/__main__.py index 9308526..6e39884 100644 --- a/linode-ansible/__main__.py +++ b/linode-ansible/__main__.py @@ -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}", diff --git a/linode-ansible/input.yaml b/linode-ansible/input.yaml index 2822ed3..662b7d5 100644 --- a/linode-ansible/input.yaml +++ b/linode-ansible/input.yaml @@ -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 diff --git a/linode-ansible/requirements.txt b/linode-ansible/requirements.txt index 18a7989..1b842b0 100644 --- a/linode-ansible/requirements.txt +++ b/linode-ansible/requirements.txt @@ -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