-
Notifications
You must be signed in to change notification settings - Fork 16
/
local_development.yml
259 lines (230 loc) · 9.4 KB
/
local_development.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
---
# Copyright 2023 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Set up a local venv-based development environment
hosts: localhost
connection: local
gather_facts: yes
tasks:
- name: Confirm prerequisite environment variables are set
ansible.builtin.assert:
that: lookup('env', item.variable) | length > 0
fail_msg: "{{ item.error_msg }}"
loop:
- variable: ANSIBLE_COLLECTIONS_PATH
error_msg: "Define your development workspace target location by setting ANSIBLE_COLLECTIONS_PATH."
- variable: VIRTUAL_ENV
error_msg: "Activate your development virtual environment."
tags: precheck
- name: Ensure credential and profile paths for SSH, CDP, and cloud providers are available
ansible.builtin.file:
path: "{{ HOME }}/{{ item }}"
state: directory
force: no
loop:
- ".ssh"
- ".cdp"
- ".aws"
- ".azure"
- ".kube"
vars:
HOME: "{{ lookup('env','HOME') }}"
tags: credentials
- name: Add package keys and repositories for Ubuntu
when: ansible_distribution == "Ubuntu"
block:
- name: Add package keys
become: yes
ansible.builtin.apt_key:
url: "{{ item }}"
state: present
loop:
- https://apt.releases.hashicorp.com/gpg # for terraform
- https://packages.cloud.google.com/apt/doc/apt-key.gpg # for kubectl & google-cloud-sdk
- https://packages.microsoft.com/keys/microsoft.asc # for azure-cli
- name: Add package repositories
become: yes
ansible.builtin.apt_repository:
repo: "{{ item.repo }}"
filename: "{{ item.name }}"
state: "present"
loop:
- name: "terraform"
repo: "deb [arch=amd64] https://apt.releases.hashicorp.com {{ ansible_distribution_release }} main"
- name: "kubectl"
repo: "deb https://apt.kubernetes.io/ kubernetes-xenial main"
- name: "google-cloud-sdk"
repo: "deb https://packages.cloud.google.com/apt cloud-sdk main"
- name: "azure-cli"
repo: "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ {{ ansible_distribution_release }} main"
tags: system
- name: Ensure availability of system commands
when: ansible_distribution != "MacOSX"
block:
- name: Install commands via package manager
become: yes
ansible.builtin.package:
name:
- pip
- git
- terraform
- kubectl
- google-cloud-sdk
- azure-cli
state: present
- name: Install commands via download
block:
# Determine if the executable already exists in path
- name: Check if commands are already available
ansible.builtin.command:
cmd: "which {{ item.exe }}"
register: command_availability
ignore_errors: true
loop:
- exe: "aws-iam-authenticator"
download_url: "https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/aws-iam-authenticator"
# If command found not to be available download and install
- name: Download and install any required commands (may take some time)
become: yes
ansible.builtin.get_url:
url: "{{ item.item.download_url }}"
dest: "/usr/local/bin/{{ item.item.exe }}"
mode: 0555
when: item.rc != 0
loop: "{{ command_availability.results }}"
- name: Ensure availability of system commands (MacOSX)
when: ansible_distribution == "MacOSX"
community.general.homebrew:
name:
- git
- terraform
- kubectl
- aws-iam-authenticator
#- azure-cli
state: present
tags: system
- name: Ensure availability of Gcloud system commands (MacOSX)
when: ansible_distribution == "MacOSX"
community.general.homebrew:
name: google-cloud-sdk
state: present
register: __osx_gcloud
failed_when: not (__osx_gcloud.msg is search("already installed") or __osx_gcloud.msg is search("Update done"))
tags: system
- name: Clone the Cloudera automation collections
ansible.builtin.git:
repo: "{{ item.repo }}"
dest: "{{ lookup('env', 'ANSIBLE_COLLECTIONS_PATH') }}/ansible_collections/cloudera/{{ item.collection}}"
version: devel
loop:
- repo: git@github.com:cloudera-labs/cloudera.cloud.git
collection: cloud
- repo: git@github.com:cloudera-labs/cloudera.cluster.git
collection: cluster
- repo: git@github.com:cloudera-labs/cloudera.exe.git
collection: exe
register: __cldr_collections
tags:
- collections
- roles
- name: Parse the Cloudera automation collection dependencies
ansible.builtin.set_fact:
collection_dependencies: "{{ collection_dependencies | default({}) | combine(galaxy.dependencies) }}"
vars:
file: "{{ item }}/galaxy.yml"
galaxy: "{{ lookup('file', file) | from_yaml }}"
loop: "{{ __cldr_collections.results | map(attribute='invocation') | map(attribute='module_args') | map(attribute='dest') | list }}"
tags: collections
- name: Install the Cloudera automation collection dependencies
community.general.ansible_galaxy_install:
type: collection
name: "{{ item.key }}:{{ item.value }}"
force: true
loop: "{{ collection_dependencies | dict2items | rejectattr('key', 'match', 'git+') | list }}"
tags: collections
- name: Parse the Cloudera automation standalone role dependencies
ansible.builtin.set_fact:
role_dependencies: "{{ role_dependencies | default([]) | union([file]) }}"
vars:
file: "{{ item }}/requirements.yml"
loop: "{{ __cldr_collections.results | map(attribute='invocation') | map(attribute='module_args') | map(attribute='dest') | list }}"
tags: roles
- name: Install the Cloudera automation role dependencies
community.general.ansible_galaxy_install:
type: role
requirements_file: "{{ item }}"
force: true
when: item is exists
environment:
ANSIBLE_ROLES_PATH: "{{ lookup('env', 'ANSIBLE_COLLECTIONS_PATH') }}/roles"
loop: "{{ role_dependencies }}"
tags: roles
- name: Install Ansible Builder
ansible.builtin.pip:
name: ansible-builder==1.2.0
state: present
tags: python
- name: Determine the dependencies of the Ansible packages
ansible.builtin.command:
ansible-builder introspect --write-pip /tmp/final_python.txt --write-bindep /tmp/final_bindep.txt $ANSIBLE_COLLECTIONS_PATH
tags: python
- name: Install Python Dependencies
ansible.builtin.pip:
requirements: /tmp/final_python.txt
state: present
tags: python
- name: Fix the azure-cli-core mismatch for ADAL-to-MSAL fiasco
ansible.builtin.pip:
name: azure-cli-core==2.30.0
state: present
tags: collections
- name: Uninstall cdpy Python library
ansible.builtin.pip:
name: cdpy
state: absent
tags: cdpy
- name: Clone the cdpy Python library project
ansible.builtin.git:
repo: "git@github.com:cloudera-labs/cdpy.git"
dest: "{{ lookup('env', 'ANSIBLE_COLLECTIONS_PATH') }}/cdpy"
version: devel
tags: cdpy
- name: Install the local cdpy library
ansible.builtin.pip:
chdir: "{{ lookup('env', 'ANSIBLE_COLLECTIONS_PATH') }}/cdpy"
editable: yes
name: .
tags: cdpy
- name: Create the environment setup script
ansible.builtin.copy:
content: |
#!/bin/sh
# Source this file to set up the development environment
export ANSIBLE_COLLECTIONS_PATH={{ lookup('env', 'ANSIBLE_COLLECTIONS_PATH') }}
export ANSIBLE_ROLES_PATH={{ lookup('env', 'ANSIBLE_COLLECTIONS_PATH') }}/roles
dest: "{{ lookup('env', 'ANSIBLE_COLLECTIONS_PATH') }}/setup-ansible-env.sh"
mode: 0755
tags: coda
- name: Print instructions
vars:
msg: |
To use this local development environment for Cloudera automation,
set the following environment variables:
export ANSIBLE_COLLECTIONS_PATH={{ lookup('env', 'ANSIBLE_COLLECTIONS_PATH') }}
export ANSIBLE_ROLES_PATH={{ lookup('env', 'ANSIBLE_COLLECTIONS_PATH') }}/roles
Or source the script, {{ lookup('env', 'ANSIBLE_COLLECTIONS_PATH') }}/setup-ansible-env.sh
source {{ lookup('env', 'CLDR_DEVELOPMENT_PATH') }}/setup-cldr-devel.sh
ansible.builtin.debug:
msg: "{{ msg.split('\n') }}"
tags: coda