Skip to content

Commit

Permalink
feat(install): create the Ansible hosts and vars files from the Terra…
Browse files Browse the repository at this point in the history
…form state
  • Loading branch information
timoa committed May 21, 2022
1 parent 01b7650 commit bbde721
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
26 changes: 26 additions & 0 deletions terraform/install.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Create the Ansible inventory file (hosts)
resource "local_file" "ansible_hosts" {
content = templatefile("${path.root}/templates/ansible_hosts.tftpl", {
public_ip = oci_core_instance.instance.public_ip
hostname = local.instance_name
user = var.instance_os_user
private_key = replace(local.private_key_path, "./", "../terraform/")
})
filename = "${path.root}/../ansible/hosts.yml"
}

# Create the Ansible variables file (vars.yml)
resource "local_file" "ansible_variables" {
content = templatefile("${path.root}/templates/ansible_vars.tftpl", {
user = var.instance_os_user
volume_iqn = oci_core_volume_attachment.volume_attachment.iqn
volume_ipv4 = oci_core_volume_attachment.volume_attachment.ipv4
volume_port = oci_core_volume_attachment.volume_attachment.port
volume_chap_username = oci_core_volume_attachment.volume_attachment.chap_username
volume_chap_password = oci_core_volume_attachment.volume_attachment.chap_secret
volume_device_name = var.block_volume_device_name
vscode_version = var.vscode_version
})
filename = "${path.root}/../ansible/group_vars/server/all.yml"
}
8 changes: 8 additions & 0 deletions terraform/templates/ansible_hosts.tftpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
server:
hosts:
${hostname}:
ansible_host: ${public_ip}
vars:
ansible_user: ${user}
ansible_ssh_private_key_file: ${private_key}
14 changes: 14 additions & 0 deletions terraform/templates/ansible_vars.tftpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# Global variables
user: ${user}

# Block Volume /data variables
volume_iqn: ${volume_iqn}
volume_ipv4: ${volume_ipv4}
volume_port: ${volume_port}
volume_chap_username: ${volume_chap_username}
volume_chap_password: ${volume_chap_password}
volume_device_name: ${volume_device_name}

# VS Code Server
vscode_version: ${vscode_version}

0 comments on commit bbde721

Please sign in to comment.