1+ ---
2+
3+ # Copyright 2021 Cloudera, Inc. All Rights Reserved.
4+ #
5+ # Licensed under the Apache License, Version 2.0 (the "License");
6+ # you may not use this file except in compliance with the License.
7+ # You may obtain a copy of the License at
8+ #
9+ # http://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing, software
12+ # distributed under the License is distributed on an "AS IS" BASIS,
13+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ # See the License for the specific language governing permissions and
15+ # limitations under the License.
16+
17+ - name : Ensure the Terraform workspace directory exists
18+ ansible.builtin.copy :
19+ src : " {{ infra__terraform_template_dir }}/infra/"
20+ dest : " {{ infra__terraform_workspace_dir }}/infra"
21+
22+ - name : Copy Terraform infra code to the artefact directory
23+ ansible.builtin.copy :
24+ src : " {{ infra__terraform_template_dir }}/infra/"
25+ dest : " {{ infra__terraform_artefact_dir }}/infra"
26+
27+ - name : Applying Terraform
28+ community.general.terraform :
29+ project_path : " {{ infra__terraform_workspace_dir }}/infra"
30+ state : " present"
31+ force_init : yes
32+ register : tf_result
33+ retries : 3
34+ delay : 10
35+ until : tf_result is succeeded
36+
37+ - name : Remove the Terraform template directory
38+ ansible.builtin.file :
39+ path : " {{ infra__terraform_template_dir }}/infra"
40+ state : absent
41+
42+ - name : Remove the Terraform workspace directory when using remote state
43+ ansible.builtin.file :
44+ path : " {{ infra__terraform_workspace_dir }}/infra"
45+ state : absent
46+ when : infra__terraform_state_storage in ['remote_s3']
47+
48+ # Get information about Dynamic Inventory VMs if created via Terraform
49+ - name : Fetch EC2 Instance info for Dynamic Inventory Nodes
50+ register : __infra_dynamic_inventory_discovered
51+ community.aws.ec2_instance_info :
52+ region : " {{ infra__region }}"
53+ filters : " {{ __filters | items2dict }}"
54+ vars :
55+ __filters :
56+ - key : " tag:{{ infra__dynamic_inventory_tag_key }}"
57+ value : " {{ infra__dynamic_inventory_tag_value }}*"
58+
59+ - name : Create output Dictionary for producing Static Inventory artefact
60+ ansible.builtin.set_fact :
61+ infra__dynamic_inventory_host_entries : " {{ infra__dynamic_inventory_host_entries | default([]) | union([host_entry]) }}"
62+ vars :
63+ host_entry : " {{ [__infra_di_item.private_dns_name, 'ansible_host=' + __infra_di_item.public_ip_address, infra__dynamic_inventory_connectors] | join(' ') }}"
64+ loop : " {{ __infra_dynamic_inventory_discovered.instances }}"
65+ loop_control :
66+ loop_var : __infra_di_item
67+
68+ # If created Utility Instance via Terraform then
69+ # need to get it's info and add to an Ansible host group
70+ - name : Add Utility Instance to host group
71+ when : infra__create_utility_service
72+ block :
73+ - name : Discover the Utility Instance details
74+ community.aws.ec2_instance_info :
75+ region : " {{ infra__region }}"
76+ filters : " {{ __filters | items2dict }}"
77+ vars :
78+ __filters :
79+ - key : " tag:Name"
80+ value : " {{ infra__namespace }}*"
81+ register : __infra_utility_compute_discovered
82+
83+ - name : Add discovered Utility Instance to host group
84+ ansible.builtin.add_host :
85+ hostname : " {{__infra_utility_compute_discovered.instances[0].public_ip_address}}"
86+ ansible_user : " {{ infra__dynamic_inventory_images_default[infra__type][infra__dynamic_inventory_os].user }}"
87+ ansible_ssh_private_key_file : " {{ (infra__private_key_file == '') | ternary(omit, infra__private_key_file) }}"
88+ groupname : cldr_utility
0 commit comments