Ancora qualche avanzamento su template linode-ansible.
This commit is contained in:
parent
7f993ce140
commit
26e4cb28f2
@ -1,13 +1,33 @@
|
||||
name: ${PROJECT}
|
||||
description: ${DESCRIPTION}
|
||||
runtime: python
|
||||
runtime:
|
||||
name: python
|
||||
options:
|
||||
toolchain: pip
|
||||
virtualenv: venv
|
||||
template:
|
||||
description: A Pulumi deployment with Linode cloud and Python, enhanced with Ansible.
|
||||
config:
|
||||
name:
|
||||
hostname:
|
||||
type: String
|
||||
default: ${PROJECT}
|
||||
description: Linode name
|
||||
description: Hostname
|
||||
domainname:
|
||||
type: String
|
||||
default: vavassori.org
|
||||
description: Domain name
|
||||
linodeType:
|
||||
type: String
|
||||
default: g6-nanode-1
|
||||
description: Linode instance type
|
||||
linodeRegion:
|
||||
type: String
|
||||
default: eu-central
|
||||
description: Linode region to load your linode on
|
||||
linodeImage:
|
||||
type: String
|
||||
default: linode/debian12
|
||||
description: Linode Image to deploy
|
||||
linode:token:
|
||||
type: String
|
||||
secret: True
|
||||
|
@ -8,24 +8,25 @@ import yaml
|
||||
from dotmap import DotMap
|
||||
|
||||
config = DotMap(yaml.safe_load(open("input.yaml").read()))
|
||||
vmname = pulumi.Config().require("name")
|
||||
hostname = pulumi.Config().require("hostname")
|
||||
domainname = pulumi.Config().require("domainname")
|
||||
|
||||
# Create a Linode resource (Linode Instance)
|
||||
instance = pulumi_linode.Instance(vmname,
|
||||
type=config.linode.type,
|
||||
region=config.linode.region,
|
||||
image=config.linode.image,
|
||||
label=vmname,
|
||||
root_pass=config.vm.root_password,
|
||||
authorized_keys=config.vm.sshkeys,
|
||||
instance = pulumi_linode.Instance(hostname,
|
||||
type=pulumi.Config().require("linodeType"),
|
||||
region=pulumi.Config().require("linodeRegion"),
|
||||
image=pulumi.Config().require("linodeImage"),
|
||||
label=hostname,
|
||||
root_pass=config.rootpassword,
|
||||
authorized_keys=config.sshkeys,
|
||||
opts=pulumi.ResourceOptions(
|
||||
custom_timeouts=pulumi.CustomTimeouts(create="2m")
|
||||
)
|
||||
)
|
||||
|
||||
zone = cloudflare.get_zone(name="vavassori.org")
|
||||
dnsrecord = cloudflare.Record(vmname,
|
||||
name=vmname,
|
||||
zone = cloudflare.get_zone(name=domainname)
|
||||
dnsrecord = cloudflare.Record(hostname,
|
||||
name=hostname,
|
||||
zone_id=zone.id,
|
||||
type="A",
|
||||
content=instance.ip_address,
|
||||
@ -35,18 +36,20 @@ dnsrecord = cloudflare.Record(vmname,
|
||||
# Creating the inventory file
|
||||
inventory = command.local.Command("a-inventory",
|
||||
create = instance.ip_address.apply(
|
||||
lambda ipaddr: f"echo '{vmname} ansible_host={ipaddr} ansible_user=root' >./inventory"
|
||||
lambda ipaddr: f"echo '{hostname} ansible_host={ipaddr} ansible_user=root hostname={hostname}.{domainname}' >./inventory"
|
||||
),
|
||||
delete = "rm -f ./inventory",
|
||||
opts = pulumi.ResourceOptions(depends_on = [ instance ])
|
||||
)
|
||||
|
||||
# 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 ])
|
||||
)
|
||||
for playbook in config.playbooks:
|
||||
shortname = playbook.split('.')[0]
|
||||
# Applying the command
|
||||
command.local.Command(f"a-deploy-{shortname}",
|
||||
create = f"ansible-playbook {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/fixhostname.yml
Normal file
6
linode-ansible/fixhostname.yml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
- hosts: all
|
||||
roles:
|
||||
- fixhostname
|
||||
become: yes
|
||||
become_user: root
|
@ -1,14 +1,10 @@
|
||||
---
|
||||
linode:
|
||||
type: g6-nanode-1
|
||||
region: eu-central
|
||||
image: linode/debian12
|
||||
|
||||
# Basic VM configuration
|
||||
vm:
|
||||
root_password: cicciopasticcio
|
||||
sshkeys:
|
||||
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso"
|
||||
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps"
|
||||
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGdTHkPCPUhvrcGgU9M6/BaEeirStM/kBnFxsLyXyelt syntaxerrormmm@kurotsuchi"
|
||||
playbook: deploy.yml
|
||||
rootpassword: cicciopasticcio
|
||||
sshkeys:
|
||||
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso"
|
||||
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps"
|
||||
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGdTHkPCPUhvrcGgU9M6/BaEeirStM/kBnFxsLyXyelt syntaxerrormmm@kurotsuchi"
|
||||
playbooks:
|
||||
- fixhostname.yml
|
||||
- deploy.yml
|
||||
|
Loading…
Reference in New Issue
Block a user