Aggiunto template per linode con ansible.
This commit is contained in:
parent
387375a253
commit
537d58efef
2
linode-ansible/.gitignore
vendored
Normal file
2
linode-ansible/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.pyc
|
||||||
|
venv/
|
5
linode-ansible/Pulumi.yaml
Normal file
5
linode-ansible/Pulumi.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
name: ${PROJECT}
|
||||||
|
description: ${DESCRIPTION}
|
||||||
|
runtime: python
|
||||||
|
template:
|
||||||
|
description: A Pulumi deployment with Linode cloud and Python, enhanced with Ansible.
|
43
linode-ansible/__main__.py
Normal file
43
linode-ansible/__main__.py
Normal file
@ -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)
|
6
linode-ansible/ansible.cfg
Normal file
6
linode-ansible/ansible.cfg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[defaults]
|
||||||
|
collections_on_ansible_version_mismatch = ignore
|
||||||
|
action_warnings = False
|
||||||
|
host_key_checking = False
|
||||||
|
inventory = inventory
|
||||||
|
log_path = ./ansible.log
|
6
linode-ansible/deploy.yml
Normal file
6
linode-ansible/deploy.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
roles:
|
||||||
|
- base_personal
|
||||||
|
become: yes
|
||||||
|
become_user: root
|
15
linode-ansible/input.yaml
Normal file
15
linode-ansible/input.yaml
Normal file
@ -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
|
5
linode-ansible/requirements.txt
Normal file
5
linode-ansible/requirements.txt
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user