diff --git a/linode-ansible/.gitignore b/linode-ansible/.gitignore new file mode 100644 index 0000000..a3807e5 --- /dev/null +++ b/linode-ansible/.gitignore @@ -0,0 +1,2 @@ +*.pyc +venv/ diff --git a/linode-ansible/Pulumi.yaml b/linode-ansible/Pulumi.yaml new file mode 100644 index 0000000..750317c --- /dev/null +++ b/linode-ansible/Pulumi.yaml @@ -0,0 +1,5 @@ +name: ${PROJECT} +description: ${DESCRIPTION} +runtime: python +template: + description: A Pulumi deployment with Linode cloud and Python, enhanced with Ansible. diff --git a/linode-ansible/__main__.py b/linode-ansible/__main__.py new file mode 100644 index 0000000..9308526 --- /dev/null +++ b/linode-ansible/__main__.py @@ -0,0 +1,43 @@ +"""A Linode Python Pulumi program""" + +import pulumi +import pulumi_linode +import pulumi_command as command +import yaml +from dotmap import DotMap + +config = DotMap(yaml.safe_load(open("input.yaml").read())) + +# Create a Linode resource (Linode Instance) +instance = pulumi_linode.Instance(config.vm.name, + type=config.linode.type, + region=config.linode.region, + image=config.linode.image, + label=config.vm.name, + root_pass=config.vm.root_password, + authorized_keys=config.vm.sshkeys, + opts=pulumi.ResourceOptions( + custom_timeouts=pulumi.CustomTimeouts(create="2m") + ) +) + +# 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" + ), + 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}", + 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) diff --git a/linode-ansible/ansible.cfg b/linode-ansible/ansible.cfg new file mode 100644 index 0000000..767948b --- /dev/null +++ b/linode-ansible/ansible.cfg @@ -0,0 +1,6 @@ +[defaults] +collections_on_ansible_version_mismatch = ignore +action_warnings = False +host_key_checking = False +inventory = inventory +log_path = ./ansible.log diff --git a/linode-ansible/deploy.yml b/linode-ansible/deploy.yml new file mode 100644 index 0000000..293b54a --- /dev/null +++ b/linode-ansible/deploy.yml @@ -0,0 +1,6 @@ +--- +- hosts: all + roles: + - base_personal + become: yes + become_user: root diff --git a/linode-ansible/input.yaml b/linode-ansible/input.yaml new file mode 100644 index 0000000..2822ed3 --- /dev/null +++ b/linode-ansible/input.yaml @@ -0,0 +1,15 @@ +--- +linode: + type: g6-nanode-1 + region: eu-central + image: linode/debian12 + +# 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" + playbook: deploy.yml diff --git a/linode-ansible/requirements.txt b/linode-ansible/requirements.txt new file mode 100644 index 0000000..18a7989 --- /dev/null +++ b/linode-ansible/requirements.txt @@ -0,0 +1,5 @@ +pulumi>=3.0.0,<4.0.0 +pulumi-linode>=4.0.0,<5.0.0 +pulumi-command>=0.4.1 +pyyaml>=6.0 +dotmap>=1.3.30