Skip to content

Commit

Permalink
user-data is now generated from a template
Browse files Browse the repository at this point in the history
  • Loading branch information
notthebee committed Sep 1, 2021
1 parent 0ff82d4 commit 6dec74a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/ansible/files/docker_persistent_data/*
!/ansible/files/docker_persistent_data/.gitkeep
cloud-init/user-data
/ansible/group_vars/fragile
/ansible/hosts
.DS_Store
10 changes: 10 additions & 0 deletions ansible/gen-user-data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- hosts: all
gather_facts: no

tasks:
- name: Generate the user-data
delegate_to: localhost
template:
src: user-data.j2
dest: ../cloud-init/user-data
6 changes: 4 additions & 2 deletions ansible/group_vars/all/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ host: "{{ duckdns_domain }}.duckdns.org"

ntp_timezone: "{{ timezone }}"

username: notthebee
locale: en-us.UTF-8

keyboard_layout: us

ssh_public_key: https://github.com/notthebee.keys
username: notthebee

guid: "1000"

Expand Down
37 changes: 37 additions & 0 deletions ansible/templates/user-data.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#cloud-config
autoinstall:
version: 1
locale: {{ locale }}
keyboard:
layout: {{ keyboard_layout }}
identity:
hostname: {{ hostname }}
password: {{ password | password_hash('sha512') }}
username: {{ username }}
network:
network:
version: 2
ethernets:
enp1s0:
critical: true
dhcp-identifier: mac
dhcp4: true
ssh:
install-server: true
authorized-keys: [ {{ ssh_public_key }} ]
storage:
grub:
reorder_uefi: False
swap:
size: 0
config:
- {ptable: gpt, serial: {{ boot_drive_serial }}, preserve: false, name: '', grub_device: false, type: disk, id: bootdrive}

- {device: bootdrive, size: 536870912, wipe: superblock, flag: boot, number: 1, preserve: false, grub_device: true, type: partition, id: efipart}
- {fstype: fat32, volume: efipart, preserve: false, type: format, id: efi}

- {device: bootdrive, size: -1, wipe: superblock, flag: linux, number: 2, preserve: false, grub_device: false, type: partition, id: rootpart}
- {fstype: ext4, volume: rootpart, preserve: false, type: format, id: root}

- {device: root, path: /, type: mount, id: rootmount}
- {device: efi, path: /boot/efi, type: mount, id: efimount}
7 changes: 6 additions & 1 deletion cloud-init/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
A user-data configuration file for an unattended installation of Ubuntu Server 20.04

## Usage:
Generate the user-data file using Ansible (make sure to change the relevant variables)
```
ansible-playbook ansible/gen-user-data.yml -l your-hostname
```

Clone the ubuntu-autoinstall-generator repository:
```
git clone https://github.com/covertsh/ubuntu-autoinstall-generator
Expand All @@ -10,7 +15,7 @@ cd ubuntu-autoinstall-generator

Install dependencies (macOS):
```
brew install p7zip gpg xorriso
brew install p7zip xorriso
```

Replace `mkisofs` with `xorriso` (at least until [#19](https://github.com/covertsh/ubuntu-autoinstall-generator/pull/19) is merged)
Expand Down
6 changes: 3 additions & 3 deletions cloud-init/user-data
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#cloud-config
autoinstall:
version: 1
locale: en_us.UTF-8
locale: en-us.UTF-8
keyboard:
layout: us
identity:
hostname: fragile
password: "$1$xyz$7ujQcnF8S3A6JQDF2fcsc/"
password: $6$cOn46nlsDBIIErKf$J5ZUpmNC8fGwgkplxj8evLN5sIYTPWnuK5THBYkVBvzlfsH58uVbpwrBxfvvoU9CB1g4JpvWwRZW6P33I/jXB/
username: notthebee
network:
network:
Expand All @@ -18,7 +18,7 @@ autoinstall:
dhcp4: true
ssh:
install-server: true
authorized-keys: [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKGUGMUo1dRl9xoDlMxQGb8dNSY+6xiEpbZWAu6FAbWw [email protected]" ]
authorized-keys: [ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKGUGMUo1dRl9xoDlMxQGb8dNSY+6xiEpbZWAu6FAbWw [email protected] ]
storage:
grub:
reorder_uefi: False
Expand Down

0 comments on commit 6dec74a

Please sign in to comment.