Professional Documents
Culture Documents
tasks:
- name: install apps
apt: name={{ item }} update_cache=yes state=latest allow_unauthenticated=yes
with_items:
- nginx
register: conf
- debug:
var: conf
1
template: src=templates/index.html.j2 dest=/usr/share/nginx/html/index.html
# This task may be required for some updates due to packages installed
- name: reboot machine
shell: sleep 2 && shutdown -r now "Ansible reboot"
async: 1
poll: 0
ignore_errors: true
# Wait for the server to come alive again
- name: wait for server to come back
local_action: wait_for
args:
host: vagrant
port: 22
state: started
delay: 30
timeout: 300
2
O ficheiro terraform que foi utilizado para instanciar as maquinas:
allow {
protocol = "tcp"
ports = ["80", "443"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["web"]
}
boot_disk {
initialize_params {
# image list can be found at:
# https://cloud.google.com/compute/docs/images
image = "ubuntu-os-cloud/ubuntu-1604-lts"
}
}
network_interface {
network = "default"
access_config {
}
}
tags = ["web"]
}
boot_disk {
initialize_params {
# image list can be found at:
# https://cloud.google.com/compute/docs/images
image = "ubuntu-os-cloud/ubuntu-1604-lts"
}
}
3
network_interface {
network = "default"
access_config {
}
}
tags = ["web"]
}
output "web" {
value = "${join(" ", google_compute_instance.webserver.*.network_interface.0.access_
}
output "lbal" {
value = "${join(" ", google_compute_instance.lbal.*.network_interface.0.access_confi
}
O conteudo do ficheiro terraform.tfstate apos montada a infraestrutura:
{
"version": 3,
"terraform_version": "0.11.0",
"serial": 5,
"lineage": "67baa84e-d85c-45ce-9ce1-e4be5c8a9382",
"modules": [
{
"path": [
"root"
],
"outputs": {
"lbal": {
"sensitive": false,
"type": "string",
"value": "35.224.139.68"
},
"web": {
"sensitive": false,
"type": "string",
"value": "35.225.152.174 35.225.50.176 35.226.199.189"
}
},
"resources": {
"google_compute_instance.lbal": {
"type": "google_compute_instance",
"depends_on": [],
"primary": {
"id": "lbal",
"attributes": {
"attached_disk.#": "0",
"boot_disk.#": "1",
"boot_disk.0.auto_delete": "true",
"boot_disk.0.device_name": "persistent-disk-0",
"boot_disk.0.disk_encryption_key_raw": "",
"boot_disk.0.disk_encryption_key_sha256": "",
"boot_disk.0.initialize_params.#": "1",
"boot_disk.0.initialize_params.0.image": "ubuntu-os-cloud/ub
"boot_disk.0.initialize_params.0.size": "0",
"boot_disk.0.initialize_params.0.type": "",
"boot_disk.0.source": "https://www.googleapis.com/compute/v1
"can_ip_forward": "false",
"cpu_platform": "Intel Sandy Bridge",
4
"create_timeout": "4",
"guest_accelerator.#": "0",
"id": "lbal",
"instance_id": "4562942350909083262",
"label_fingerprint": "42WmSpB8rSM=",
"machine_type": "f1-micro",
"metadata.%": "0",
"metadata_fingerprint": "hUswLMpmJrE=",
"min_cpu_platform": "",
"name": "lbal",
"network_interface.#": "1",
"network_interface.0.access_config.#": "1",
"network_interface.0.access_config.0.assigned_nat_ip": "35.2
"network_interface.0.access_config.0.nat_ip": "35.224.139.68
"network_interface.0.address": "10.128.0.3",
"network_interface.0.alias_ip_range.#": "0",
"network_interface.0.name": "nic0",
"network_interface.0.network": "https://www.googleapis.com/c
"network_interface.0.network_ip": "10.128.0.3",
"network_interface.0.subnetwork": "https://www.googleapis.co
"network_interface.0.subnetwork_project": "agiit1718-42",
"project": "agiit1718-42",
"scheduling.#": "1",
"scheduling.0.automatic_restart": "true",
"scheduling.0.on_host_maintenance": "MIGRATE",
"scheduling.0.preemptible": "false",
"scratch_disk.#": "0",
"self_link": "https://www.googleapis.com/compute/v1/projects
"service_account.#": "0",
"tags.#": "1",
"tags.365508689": "web",
"tags_fingerprint": "3d9fNIIa_10=",
"zone": "us-central1-a"
},
"meta": {
"schema_version": "6"
},
"tainted": false
},
"deposed": [],
"provider": "provider.google"
},
"google_compute_instance.webserver.0": {
"type": "google_compute_instance",
"depends_on": [],
"primary": {
"id": "web1",
"attributes": {
"attached_disk.#": "0",
"boot_disk.#": "1",
"boot_disk.0.auto_delete": "true",
"boot_disk.0.device_name": "persistent-disk-0",
"boot_disk.0.disk_encryption_key_raw": "",
"boot_disk.0.disk_encryption_key_sha256": "",
"boot_disk.0.initialize_params.#": "1",
"boot_disk.0.initialize_params.0.image": "ubuntu-os-cloud/ub
"boot_disk.0.initialize_params.0.size": "0",
"boot_disk.0.initialize_params.0.type": "",
5
"boot_disk.0.source": "https://www.googleapis.com/compute/v1
"can_ip_forward": "false",
"cpu_platform": "Intel Sandy Bridge",
"create_timeout": "4",
"guest_accelerator.#": "0",
"id": "web1",
"instance_id": "4846001951508945342",
"label_fingerprint": "42WmSpB8rSM=",
"machine_type": "f1-micro",
"metadata.%": "0",
"metadata_fingerprint": "hUswLMpmJrE=",
"min_cpu_platform": "",
"name": "web1",
"network_interface.#": "1",
"network_interface.0.access_config.#": "1",
"network_interface.0.access_config.0.assigned_nat_ip": "35.2
"network_interface.0.access_config.0.nat_ip": "35.225.152.17
"network_interface.0.address": "10.128.0.2",
"network_interface.0.alias_ip_range.#": "0",
"network_interface.0.name": "nic0",
"network_interface.0.network": "https://www.googleapis.com/c
"network_interface.0.network_ip": "10.128.0.2",
"network_interface.0.subnetwork": "https://www.googleapis.co
"network_interface.0.subnetwork_project": "agiit1718-42",
"project": "agiit1718-42",
"scheduling.#": "1",
"scheduling.0.automatic_restart": "true",
"scheduling.0.on_host_maintenance": "MIGRATE",
"scheduling.0.preemptible": "false",
"scratch_disk.#": "0",
"self_link": "https://www.googleapis.com/compute/v1/projects
"service_account.#": "0",
"tags.#": "1",
"tags.365508689": "web",
"tags_fingerprint": "3d9fNIIa_10=",
"zone": "us-central1-a"
},
"meta": {
"schema_version": "6"
},
"tainted": false
},
"deposed": [],
"provider": "provider.google"
},
"google_compute_instance.webserver.1": {
"type": "google_compute_instance",
"depends_on": [],
"primary": {
"id": "web2",
"attributes": {
"attached_disk.#": "0",
"boot_disk.#": "1",
"boot_disk.0.auto_delete": "true",
"boot_disk.0.device_name": "persistent-disk-0",
"boot_disk.0.disk_encryption_key_raw": "",
"boot_disk.0.disk_encryption_key_sha256": "",
"boot_disk.0.initialize_params.#": "1",
6
"boot_disk.0.initialize_params.0.image": "ubuntu-os-cloud/ub
"boot_disk.0.initialize_params.0.size": "0",
"boot_disk.0.initialize_params.0.type": "",
"boot_disk.0.source": "https://www.googleapis.com/compute/v1
"can_ip_forward": "false",
"cpu_platform": "Intel Sandy Bridge",
"create_timeout": "4",
"guest_accelerator.#": "0",
"id": "web2",
"instance_id": "7321754558441819774",
"label_fingerprint": "42WmSpB8rSM=",
"machine_type": "f1-micro",
"metadata.%": "0",
"metadata_fingerprint": "hUswLMpmJrE=",
"min_cpu_platform": "",
"name": "web2",
"network_interface.#": "1",
"network_interface.0.access_config.#": "1",
"network_interface.0.access_config.0.assigned_nat_ip": "35.2
"network_interface.0.access_config.0.nat_ip": "35.225.50.176
"network_interface.0.address": "10.128.0.4",
"network_interface.0.alias_ip_range.#": "0",
"network_interface.0.name": "nic0",
"network_interface.0.network": "https://www.googleapis.com/c
"network_interface.0.network_ip": "10.128.0.4",
"network_interface.0.subnetwork": "https://www.googleapis.co
"network_interface.0.subnetwork_project": "agiit1718-42",
"project": "agiit1718-42",
"scheduling.#": "1",
"scheduling.0.automatic_restart": "true",
"scheduling.0.on_host_maintenance": "MIGRATE",
"scheduling.0.preemptible": "false",
"scratch_disk.#": "0",
"self_link": "https://www.googleapis.com/compute/v1/projects
"service_account.#": "0",
"tags.#": "1",
"tags.365508689": "web",
"tags_fingerprint": "3d9fNIIa_10=",
"zone": "us-central1-a"
},
"meta": {
"schema_version": "6"
},
"tainted": false
},
"deposed": [],
"provider": "provider.google"
},
"google_compute_instance.webserver.2": {
"type": "google_compute_instance",
"depends_on": [],
"primary": {
"id": "web3",
"attributes": {
"attached_disk.#": "0",
"boot_disk.#": "1",
"boot_disk.0.auto_delete": "true",
"boot_disk.0.device_name": "persistent-disk-0",
7
"boot_disk.0.disk_encryption_key_raw": "",
"boot_disk.0.disk_encryption_key_sha256": "",
"boot_disk.0.initialize_params.#": "1",
"boot_disk.0.initialize_params.0.image": "ubuntu-os-cloud/ub
"boot_disk.0.initialize_params.0.size": "0",
"boot_disk.0.initialize_params.0.type": "",
"boot_disk.0.source": "https://www.googleapis.com/compute/v1
"can_ip_forward": "false",
"cpu_platform": "Intel Sandy Bridge",
"create_timeout": "4",
"guest_accelerator.#": "0",
"id": "web3",
"instance_id": "6202403158170635902",
"label_fingerprint": "42WmSpB8rSM=",
"machine_type": "f1-micro",
"metadata.%": "0",
"metadata_fingerprint": "hUswLMpmJrE=",
"min_cpu_platform": "",
"name": "web3",
"network_interface.#": "1",
"network_interface.0.access_config.#": "1",
"network_interface.0.access_config.0.assigned_nat_ip": "35.2
"network_interface.0.access_config.0.nat_ip": "35.226.199.18
"network_interface.0.address": "10.128.0.5",
"network_interface.0.alias_ip_range.#": "0",
"network_interface.0.name": "nic0",
"network_interface.0.network": "https://www.googleapis.com/c
"network_interface.0.network_ip": "10.128.0.5",
"network_interface.0.subnetwork": "https://www.googleapis.co
"network_interface.0.subnetwork_project": "agiit1718-42",
"project": "agiit1718-42",
"scheduling.#": "1",
"scheduling.0.automatic_restart": "true",
"scheduling.0.on_host_maintenance": "MIGRATE",
"scheduling.0.preemptible": "false",
"scratch_disk.#": "0",
"self_link": "https://www.googleapis.com/compute/v1/projects
"service_account.#": "0",
"tags.#": "1",
"tags.365508689": "web",
"tags_fingerprint": "3d9fNIIa_10=",
"zone": "us-central1-a"
},
"meta": {
"schema_version": "6"
},
"tainted": false
},
"deposed": [],
"provider": "provider.google"
}
},
"depends_on": []
}
]
}