From 6e538627db08bd743f64bb0efc1d431506482b58 Mon Sep 17 00:00:00 2001 From: Jack Ivanov Date: Mon, 6 Mar 2017 00:56:15 +0300 Subject: [PATCH] gce inventory #30 --- roles/cloud-gce/tasks/main.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/roles/cloud-gce/tasks/main.yml b/roles/cloud-gce/tasks/main.yml index e94d0d5..6464cba 100644 --- a/roles/cloud-gce/tasks/main.yml +++ b/roles/cloud-gce/tasks/main.yml @@ -12,6 +12,8 @@ credentials_file: "{{ credentials_file }}" project_id: "{{ credentials_file_lookup.project_id }}" metadata: '{"sshKeys":"root:{{ ssh_public_key_lookup }}"}' + tags: + - "environment: algo" register: google_vm - name: Add the instance to an inventory group @@ -38,3 +40,17 @@ - set_fact: cloud_instance_ip: "{{ google_vm.instance_data[0].public_ip }}" + +- name: Ensure the group gce exists in the dynamic inventory file + lineinfile: + state: present + dest: configs/inventory.dynamic + line: '[gce]' + +- name: Populate the dynamic inventory + lineinfile: + state: present + dest: configs/inventory.dynamic + insertafter: '\[gce\]' + regexp: "^{{ google_vm.instance_data[0].public_ip }}.*" + line: "{{ google_vm.instance_data[0].public_ip }}"