This repo contains boilerplate and starting points for a tour through infrastructure as code.
provider "hcloud" {
token = var.hcloud_token
}
resource "hcloud_server" "super_duper_server" {
name = "super-duper-server-1"
...
}
variable "image-name" {
type = string
default = "debian-12"
}
output "instance_ip" {
value = hcloud_server.super_duper_server.public_ip
}
terraform init
terraform plan
terraform apply
terraform destroy
---
# inventory.yaml
web:
hosts:
super-duper-server-1.hetzner.com:
---
# install_nginx.yaml
- name: Install and Configure Nginx
hosts: web
tasks:
- name: Install Nginx
ansible.builtin.apt:
name: nginx
state: present
- name: Ensure Nginx is running
ansible.builtin.service:
name: nginx
state: started
---
- name: Use Variables
hosts: web
vars:
nginx_port: 80
tasks:
- name: Install Nginx
ansible.builtin.apt:
name: nginx
state: present
- name: Configure Nginx
ansible.builtin.template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
---
- name: Use Loops and Conditionals
hosts: web
tasks:
- name: Create Users
ansible.builtin.user:
name: "{{ item }}"
state: present
loop:
- user1
- user2
when: ansible_os_family == "Debian"
---
- name: Restart Nginx if Config Changed
hosts: web
tasks:
- name: Update Nginx Config
ansible.builtin.template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
notify:
- restart nginx
handlers:
- name: restart nginx
ansible.builtin.service:
name: nginx
state: restarted
ansible-playbook -i inventory.yaml install_nginx.yml
ansible-galaxy collection install hetzner.hcloud