diff --git a/google_cloud.yml b/google_cloud.yml index 80da93b..504f82f 100644 --- a/google_cloud.yml +++ b/google_cloud.yml @@ -3,72 +3,64 @@ gather_facts: false vars: - regions: - "1": "East US" - "2": "West US" - "3": "South Central US" - "4": "North Europe" - "5": "East Asia" - "6": "Japan East" - "7": "West Europe" - "8": "Southeast Asia" - "9": "Japan West" - "10": "North Central US" - "11": "Central US" - "12": "Brazil South" - "13": "East US 2" - "14": "Australia Southeast" - "15": "Australia East" + zones: + "1": "us-central1-a" + "2": "us-central1-b" + "3": "us-central1-c" + "4": "us-central1-f" + "5": "us-east1-b" + "6": "us-east1-c" + "7": "us-east1-d" + "8": "europe-west1-b" + "9": "europe-west1-c" + "10": "europe-west1-d" + "11": "asia-east1-a" + "12": "asia-east1-b" + "13": "asia-east1-c" - #vars_prompt: - #- name: "azure_subscription_id" - #prompt: "Enter your subscription ID (https://blogs.msdn.microsoft.com/mschray/2015/05/13/getting-your-azure-guid-subscription-id/):\n" - #private: yes + vars_prompt: + - name: "credentials_file" + prompt: "Enter the local path to your credentials JSON file [ex: ~/gogle_cloud.json] (https://support.google.com/cloud/answer/6158849?hl=en&ref_topic=6262490#serviceaccounts):\n" + private: no + + - name: "ssh_public_key" + prompt: "Enter the local path to your SSH public key [ex: ~/.ssh/id_rsa.pub] :\n" + private: no - #- name: "management_cert_path" - #prompt: "Enter the local path to your management cert [ex: ~/.ssh/id_rsa.pub] (https://azure.microsoft.com/en-us/documentation/articles/azure-api-management-certs/):\n" - #private: no + - name: "zone" + prompt: > + What zone should the server be located in? + 1. Central US (Iowa A) + 2. Central US (Iowa B) + 3. Central US (Iowa C) + 4. Central US (Iowa F) + 5. Eastern US (South Carolina B) + 6. Eastern US (South Carolina C) + 7. Eastern US (South Carolina D) + 8. Western Europe (Belgium B) + 9. Western Europe (Belgium C) + 10. Western Europe (Belgium D) + 11. East Asia (Taiwan A) + 12. East Asia (Taiwan B) + 13. East Asia (Taiwan C) + Please choose the number of your zone. Press enter for default (#8) zone. + default: "8" + private: no - #- name: "ssh_public_key" - #prompt: "Enter the local path to your SSH public key [ex: ~/.ssh/id_rsa.pub] :\n" - #private: no - - #- name: "region" - #prompt: > - #What region should the server be located in? - #1. East US - #2. West US - #3. South Central US - #4. North Europe - #5. East Asia - #6. Japan East - #7. West Europe - #8. Southeast Asia - #9. Japan West - #10. North Central US - #11. Central US - #12. Brazil South - #13. East US 2 - #14. Australia Southeast - #15. Australia East - #Enter the number of your desired region: - #default: "7" - #private: no + - name: "server_name" + prompt: "Name the vpn server:\n" + default: "algo" + private: no - #- name: "azure_server_name" - #prompt: "Name the vpn server:\n" - #default: "algo.local" - #private: no + - name: "dns_enabled" + prompt: "Do you want to use a local DNS resolver to block ads while surfing? (Y or N):\n" + default: "Y" + private: no - #- name: "dns_enabled" - #prompt: "Do you want to use a local DNS resolver to block ads while surfing? (Y or N):\n" - #default: "Y" - #private: no - - #- name: "auditd_enabled" - #prompt: "Do you want to use auditd ? (Y or N):\n" - #default: "Y" - #private: no + - name: "auditd_enabled" + prompt: "Do you want to use auditd ? (Y or N):\n" + default: "Y" + private: no roles: - google_cloud diff --git a/roles/google_cloud/tasks/main.yml b/roles/google_cloud/tasks/main.yml index ed3b6f3..34ec713 100644 --- a/roles/google_cloud/tasks/main.yml +++ b/roles/google_cloud/tasks/main.yml @@ -1,13 +1,29 @@ -- name: Launch instances +- set_fact: + credentials_file_lookup: "{{ lookup('file', '{{ credentials_file }}') }}" + ssh_public_key_lookup: "{{ lookup('file', '{{ ssh_public_key }}') }}" + +- name: "Creating a droplet..." gce: - instance_names: dev - zone: us-central1-b + instance_names: "{{ server_name }}" + zone: "{{ zones[zone] }}" machine_type: n1-standard-1 - image: debian-7-wheezy - service_account_email: e601809@gmail.com - credentials_file: '/home/jack/ownCloud/Clouds/Google/My First Project-72e386228f5e.json' - project_id: algo-833@storied-bearing-140310.iam.gserviceaccount.com + image: ubuntu-1604 + service_account_email: "{{ credentials_file_lookup.client_email }}" + credentials_file: "{{ credentials_file }}" + project_id: "{{ credentials_file_lookup.project_id }}" + metadata: '{"sshKeys":"root:{{ ssh_public_key_lookup }}"}' register: google_vm -- debug: msg="{{ google_vm }}" +- name: Add the droplet to an inventory group + add_host: + name: "{{ google_vm.instance_data[0].public_ip}}" + groups: vpn-host + ansible_ssh_user: ubuntu + ansible_python_interpreter: "/usr/bin/python2.7" + dns_enabled: "{{ dns_enabled }}" + auditd_enabled: " {{ auditd_enabled }}" + +- name: Wait for SSH to become available + local_action: "wait_for port=22 host={{ google_vm.instance_data[0].public_ip }} timeout=320" + diff --git a/run b/run index 6041d90..187e598 100755 --- a/run +++ b/run @@ -9,8 +9,8 @@ algo_provisioning () { 4. Google-cloud 0. Local installation (non-cloud or a server already deployed) - Enter the number of your desired provider - : " +Enter the number of your desired provider +: " read N