Skip to content

Commit

Permalink
feat(ansible): add common + devops deps (if enabled) with Ansible
Browse files Browse the repository at this point in the history
It install OS updates, VS Code Server
  • Loading branch information
timoa committed May 23, 2022
1 parent 1710fef commit 4598921
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 4 deletions.
12 changes: 12 additions & 0 deletions ansible/playbooks/common/os-updates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# This playbook install the common packages
- hosts: server
become: true
gather_facts: false

tasks:
- name: Update apt-get repo and cache
apt: update_cache=yes force_apt_get=yes cache_valid_time=3600

- name: Upgrade all apt packages
apt: upgrade=dist force_apt_get=yes
15 changes: 15 additions & 0 deletions ansible/playbooks/common/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

BASEDIR=$(dirname $0)

# Install the Ansible roles
ansible-galaxy install -r $BASEDIR/roles.yml

# Install updates
ansible-playbook -i $BASEDIR/../../hosts.yml $BASEDIR/os-updates.yml

# Install VS Code Server
ansible-playbook -i $BASEDIR/../../hosts.yml $BASEDIR/vscode-server.yml

# Install the other required packages
# ansible-playbook -i $BASEDIR/../../hosts.yml $BASEDIR/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- name: Enable the VSCode Server service
ansible.builtin.systemd:
name: "code-server@{{user}}"
state: started
enabled: yes
masked: no

Expand Down
12 changes: 12 additions & 0 deletions ansible/playbooks/for-devops/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# This playbook install the common packages
- hosts: server
become: true
gather_facts: false

roles:
- role: geerlingguy.helm
helm_arch: arm64

- role: geerlingguy.docker_arm
docker_install_compose: false
5 changes: 5 additions & 0 deletions ansible/playbooks/for-devops/roles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Docker
- name: geerlingguy.docker

# Helm
- name: geerlingguy.helm
9 changes: 9 additions & 0 deletions ansible/playbooks/for-devops/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

BASEDIR=$(dirname $0)

# Install the Ansible roles
ansible-galaxy install -r $BASEDIR/roles.yml

# Run the playbook
ansible-playbook -i $BASEDIR/../../hosts.yml $BASEDIR/playbook.yml
23 changes: 19 additions & 4 deletions terraform/install.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,31 @@ resource "local_file" "ansible_variables" {
}

#############################
# Install
# Install the packages
#############################

# Install VS Code Server
resource "null_resource" "vscode_install" {
# Install Common roles
resource "null_resource" "common_playbook" {
depends_on = [
null_resource.mount_data_volume
]

provisioner "local-exec" {
command = "ansible-playbook -i ${path.root}/../ansible/hosts.yml ${path.root}/../ansible/playbooks/vscode-server.yml"
command = "bash ${path.root}/../ansible/playbooks/common/run.sh"
}
}

# Install DevOps roles (if enabled)
resource "null_resource" "devops_roles" {

count = var.install_devops_deps ? 1 : 0

depends_on = [
null_resource.mount_data_volume,
null_resource.common_playbook,
]

provisioner "local-exec" {
command = "bash ${path.root}/../ansible/playbooks/for-devops/run.sh"
}
}
10 changes: 10 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ variable "vscode_version" {
default = "4.4.0"
}

#############################
# VS Code Server Dependencies
#############################

variable "install_devops_deps" {
type = bool
description = "Install DevOps tools like Docker, Helm, Terraform, Ansible, etc."
default = false
}

#############################
# Key Pairs
#############################
Expand Down

0 comments on commit 4598921

Please sign in to comment.