terraform-ssh-remote-exec.tf 977 Bytes
Newer Older
Ryan Jones's avatar
updates    
Ryan Jones committed
1
resource "openstack" "vm" {
Ryan Randles Jones's avatar
Ryan Randles Jones committed
2
3
4

  provisioner "remote-exec" {
    inline = [
5
6
7
8
9
    "hostnamectl set-hostname ohpc",
    "yum install -y epel-release",
    "yum install -y ansible git vim bash-completion",
    "yum install -y NetworkManager",
    "systemctl restart NetworkManager",
Ryan Jones's avatar
updates    
Ryan Jones committed
10
    "nmcli con mod 'Wired connection 1' connection.id 'eth1'",
Ryan Randles Jones's avatar
Ryan Randles Jones committed
11
    ]
12
13
14
15
16

    connection {
        host        = "${self.ipv4_address}" # The `self` variable is like `this` in many programming languages
        type        = "ssh"                  # in this case, `self` is the resource (the server).
        user        = "root"
Ryan Jones's avatar
updates    
Ryan Jones committed
17
        private_key = "${file("~/.ssh/id_rsa")}"
18
    }
Ryan Randles Jones's avatar
Ryan Randles Jones committed
19
  }
20
21
22
23
24
25
26
27
28
29

  provisioner "local-exec" {
    environment {
    PUBLIC_IP  = "${self.ipv4_address}"
    PRIVATE_IP = "${self.ipv4_address_private}"
    }

    working_dir = "$HOME/terraform-first-instance/terraform-openstack/CRI_XCBC/"
    command     = "ansible-playbook -c local -i hosts -l `hostname` site.yaml -b,"
    }
Ryan Jones's avatar
updates    
Ryan Jones committed
30
}