Add ansible to pipeline
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Kasper Juul Hermansen 2022-02-19 18:18:19 +01:00
parent 81abb30846
commit 170c5e0730
Signed by: kjuulh
GPG Key ID: 0F95C140730F2F23
6 changed files with 32 additions and 35 deletions

View File

@ -26,3 +26,5 @@ steps:
- terraform init -backend-config="access_key=$ACCESS_KEY" -backend-config="secret_key=$SECRET_KEY" - terraform init -backend-config="access_key=$ACCESS_KEY" -backend-config="secret_key=$SECRET_KEY"
- terraform validate - terraform validate
- terraform apply -auto-approve -var "hcloud_token=$HCLOUD_TOKEN" -var "pvt_key=../ssh_keys/id_ed25519" -var "pub_key=../ssh_keys/id_ed25519.pub" -var "hcloud_serverctl_ssh_key_id=$HCLOUD_SSH_KEY_ID" - terraform apply -auto-approve -var "hcloud_token=$HCLOUD_TOKEN" -var "pvt_key=../ssh_keys/id_ed25519" -var "pub_key=../ssh_keys/id_ed25519.pub" -var "hcloud_serverctl_ssh_key_id=$HCLOUD_SSH_KEY_ID"
- cd ansible
- ANSIBLE_HOST_KEY_CHECKING=False /usr/bin/ansible-playbook -u root --key-file '../../ssh_keys/id_ed25519' server-install.yml

View File

@ -0,0 +1,2 @@
[serverctl_master_hosts]
65.21.153.18

View File

@ -1,6 +1,6 @@
- become: yes - become: yes
hosts: all hosts: all
name: apache-install name: server-install
tasks: tasks:
- name: Add the user 'kjuulh' and add it to 'sudo' - name: Add the user 'kjuulh' and add it to 'sudo'
user: user:
@ -14,22 +14,3 @@
- name: Wait for apt to unlock - name: Wait for apt to unlock
become: yes become: yes
shell: while sudo fuser /var/lib/dpkg/lock >/dev/null >2&1; do sleep 5; done; shell: while sudo fuser /var/lib/dpkg/lock >/dev/null >2&1; do sleep 5; done;
- name: Install apache2
apt:
name: apache2
update_cache: yes
state: latest
- name: enable mod_rewrite
apache2_module:
name: rewrite
state: present
notify:
- Restart apache2
handlers:
- name: Restart apache2
service:
name: apache2
state: restarted

View File

@ -33,7 +33,7 @@ resource "null_resource" "configure_serverctl_master" {
count = var.serverctl_master_count count = var.serverctl_master_count
provisioner "local-exec" { provisioner "local-exec" {
command = "ANSIBLE_HOST_KEY_CHECKING=False /usr/bin/ansible-playbook -u root -i '${element(hcloud_server.serverctl_master.*.ipv4_address, 0)},' --private-key ${var.pvt_key} -e 'pub_key=${var.pub_key}' apache-install.yml" command = "ANSIBLE_HOST_KEY_CHECKING=False /usr/bin/ansible-playbook -u root -i '${element(hcloud_server.serverctl_master.*.ipv4_address, 0)},' --private-key ${var.pvt_key} -e 'pub_key=${var.pub_key}' server-install.yml"
} }
triggers = { triggers = {
@ -43,7 +43,16 @@ resource "null_resource" "configure_serverctl_master" {
output "master_ipv4_addresses" { output "master_ipv4_addresses" {
value = { value = {
for serverctl in hcloud_server.serverctl_master: for serverctl in hcloud_server.serverctl_master :
serverctl.name => serverctl.ipv4_address serverctl.name => serverctl.ipv4_address
} }
} }
resource "local_file" "hosts_cfg" {
content = templatefile("${path.module}/templates/hosts.tpl",
{
serverctl_masters = hcloud_server.serverctl_master.*.ipv4_address
}
)
filename = "ansible/inventory/hosts.cfg"
}

View File

@ -33,4 +33,3 @@ provider "hcloud" {
variable "hcloud_serverctl_ssh_key_id" {} variable "hcloud_serverctl_ssh_key_id" {}
variable "pvt_key" {} variable "pvt_key" {}
variable "pub_key" {} variable "pub_key" {}

View File

@ -0,0 +1,4 @@
[serverctl_master_hosts]
%{ for ip in serverctl_masters ~}
${ip}
%{ endfor ~}