|
1 | 1 | - block:
|
2 |
| - - name: Include prompts |
3 |
| - import_tasks: prompts.yml |
4 |
| - |
5 |
| - - name: Set additional facts |
6 |
| - set_fact: |
7 |
| - algo_do_region: >- |
8 |
| - {% if region is defined %}{{ region }} |
9 |
| - {%- elif _algo_region.user_input is defined and _algo_region.user_input != "" %}{{ do_regions[_algo_region.user_input | int -1 ]['slug'] }} |
10 |
| - {%- else %}{{ do_regions[default_region | int - 1]['slug'] }}{% endif %} |
11 |
| - public_key: "{{ lookup('file', '{{ SSH_keys.public }}') }}" |
| 2 | + - name: Build python virtual environment |
| 3 | + import_tasks: venv.yml |
12 | 4 |
|
13 | 5 | - block:
|
14 |
| - - name: "Delete the existing Algo SSH keys" |
15 |
| - digital_ocean: |
16 |
| - state: absent |
17 |
| - command: ssh |
18 |
| - api_token: "{{ algo_do_token }}" |
19 |
| - name: "{{ SSH_keys.comment }}" |
20 |
| - register: ssh_keys |
21 |
| - until: ssh_keys.changed != true |
22 |
| - retries: 10 |
23 |
| - delay: 1 |
| 6 | + - name: Include prompts |
| 7 | + import_tasks: prompts.yml |
24 | 8 |
|
25 |
| - rescue: |
26 |
| - - name: Collect the fail error |
27 |
| - digital_ocean: |
28 |
| - state: absent |
29 |
| - command: ssh |
30 |
| - api_token: "{{ algo_do_token }}" |
31 |
| - name: "{{ SSH_keys.comment }}" |
32 |
| - register: ssh_keys |
33 |
| - ignore_errors: yes |
| 9 | + - name: Set additional facts |
| 10 | + set_fact: |
| 11 | + algo_do_region: >- |
| 12 | + {% if region is defined %}{{ region }} |
| 13 | + {%- elif _algo_region.user_input is defined and _algo_region.user_input != "" %}{{ do_regions[_algo_region.user_input | int -1 ]['slug'] }} |
| 14 | + {%- else %}{{ do_regions[default_region | int - 1]['slug'] }}{% endif %} |
| 15 | + public_key: "{{ lookup('file', '{{ SSH_keys.public }}') }}" |
34 | 16 |
|
35 |
| - - debug: var=ssh_keys |
| 17 | + - block: |
| 18 | + - name: "Delete the existing Algo SSH keys" |
| 19 | + digital_ocean: |
| 20 | + state: absent |
| 21 | + command: ssh |
| 22 | + api_token: "{{ algo_do_token }}" |
| 23 | + name: "{{ SSH_keys.comment }}" |
| 24 | + register: ssh_keys |
| 25 | + until: ssh_keys.changed != true |
| 26 | + retries: 10 |
| 27 | + delay: 1 |
36 | 28 |
|
37 |
| - - fail: |
38 |
| - msg: "Please, ensure that your API token is not read-only." |
| 29 | + rescue: |
| 30 | + - name: Collect the fail error |
| 31 | + digital_ocean: |
| 32 | + state: absent |
| 33 | + command: ssh |
| 34 | + api_token: "{{ algo_do_token }}" |
| 35 | + name: "{{ SSH_keys.comment }}" |
| 36 | + register: ssh_keys |
| 37 | + ignore_errors: yes |
39 | 38 |
|
40 |
| - - name: "Upload the SSH key" |
41 |
| - digital_ocean: |
42 |
| - state: present |
43 |
| - command: ssh |
44 |
| - ssh_pub_key: "{{ public_key }}" |
45 |
| - api_token: "{{ algo_do_token }}" |
46 |
| - name: "{{ SSH_keys.comment }}" |
47 |
| - register: do_ssh_key |
| 39 | + - debug: var=ssh_keys |
48 | 40 |
|
49 |
| - - name: "Creating a droplet..." |
50 |
| - digital_ocean: |
51 |
| - state: present |
52 |
| - command: droplet |
53 |
| - name: "{{ algo_server_name }}" |
54 |
| - region_id: "{{ algo_do_region }}" |
55 |
| - size_id: "{{ cloud_providers.digitalocean.size }}" |
56 |
| - image_id: "{{ cloud_providers.digitalocean.image }}" |
57 |
| - ssh_key_ids: "{{ do_ssh_key.ssh_key.id }}" |
58 |
| - unique_name: yes |
59 |
| - api_token: "{{ algo_do_token }}" |
60 |
| - ipv6: yes |
61 |
| - register: do |
| 41 | + - fail: |
| 42 | + msg: "Please, ensure that your API token is not read-only." |
62 | 43 |
|
63 |
| - - set_fact: |
64 |
| - cloud_instance_ip: "{{ do.droplet.ip_address }}" |
65 |
| - ansible_ssh_user: root |
| 44 | + - name: "Upload the SSH key" |
| 45 | + digital_ocean: |
| 46 | + state: present |
| 47 | + command: ssh |
| 48 | + ssh_pub_key: "{{ public_key }}" |
| 49 | + api_token: "{{ algo_do_token }}" |
| 50 | + name: "{{ SSH_keys.comment }}" |
| 51 | + register: do_ssh_key |
66 | 52 |
|
67 |
| - - name: Tag the droplet |
68 |
| - digital_ocean_tag: |
69 |
| - name: "Environment:Algo" |
70 |
| - resource_id: "{{ do.droplet.id }}" |
71 |
| - api_token: "{{ algo_do_token }}" |
72 |
| - state: present |
| 53 | + - name: "Creating a droplet..." |
| 54 | + digital_ocean: |
| 55 | + state: present |
| 56 | + command: droplet |
| 57 | + name: "{{ algo_server_name }}" |
| 58 | + region_id: "{{ algo_do_region }}" |
| 59 | + size_id: "{{ cloud_providers.digitalocean.size }}" |
| 60 | + image_id: "{{ cloud_providers.digitalocean.image }}" |
| 61 | + ssh_key_ids: "{{ do_ssh_key.ssh_key.id }}" |
| 62 | + unique_name: yes |
| 63 | + api_token: "{{ algo_do_token }}" |
| 64 | + ipv6: yes |
| 65 | + register: do |
73 | 66 |
|
74 |
| - - block: |
75 |
| - - name: "Delete the new Algo SSH key" |
76 |
| - digital_ocean: |
77 |
| - state: absent |
78 |
| - command: ssh |
79 |
| - api_token: "{{ algo_do_token }}" |
80 |
| - name: "{{ SSH_keys.comment }}" |
81 |
| - register: ssh_keys |
82 |
| - until: ssh_keys.changed != true |
83 |
| - retries: 10 |
84 |
| - delay: 1 |
| 67 | + - set_fact: |
| 68 | + cloud_instance_ip: "{{ do.droplet.ip_address }}" |
| 69 | + ansible_ssh_user: root |
| 70 | + |
| 71 | + - name: Tag the droplet |
| 72 | + digital_ocean_tag: |
| 73 | + name: "Environment:Algo" |
| 74 | + resource_id: "{{ do.droplet.id }}" |
| 75 | + api_token: "{{ algo_do_token }}" |
| 76 | + state: present |
| 77 | + |
| 78 | + - block: |
| 79 | + - name: "Delete the new Algo SSH key" |
| 80 | + digital_ocean: |
| 81 | + state: absent |
| 82 | + command: ssh |
| 83 | + api_token: "{{ algo_do_token }}" |
| 84 | + name: "{{ SSH_keys.comment }}" |
| 85 | + register: ssh_keys |
| 86 | + until: ssh_keys.changed != true |
| 87 | + retries: 10 |
| 88 | + delay: 1 |
85 | 89 |
|
86 |
| - rescue: |
87 |
| - - name: Collect the fail error |
88 |
| - digital_ocean: |
89 |
| - state: absent |
90 |
| - command: ssh |
91 |
| - api_token: "{{ algo_do_token }}" |
92 |
| - name: "{{ SSH_keys.comment }}" |
93 |
| - register: ssh_keys |
94 |
| - ignore_errors: yes |
| 90 | + rescue: |
| 91 | + - name: Collect the fail error |
| 92 | + digital_ocean: |
| 93 | + state: absent |
| 94 | + command: ssh |
| 95 | + api_token: "{{ algo_do_token }}" |
| 96 | + name: "{{ SSH_keys.comment }}" |
| 97 | + register: ssh_keys |
| 98 | + ignore_errors: yes |
95 | 99 |
|
96 |
| - - debug: var=ssh_keys |
| 100 | + - debug: var=ssh_keys |
97 | 101 |
|
98 |
| - - fail: |
99 |
| - msg: "Please, ensure that your API token is not read-only." |
| 102 | + - fail: |
| 103 | + msg: "Please, ensure that your API token is not read-only." |
| 104 | + environment: |
| 105 | + PYTHONPATH: "{{ digitalocean_venv }}/lib/python2.7/site-packages/" |
100 | 106 | rescue:
|
101 | 107 | - debug: var=fail_hint
|
102 | 108 | tags: always
|
|
0 commit comments