Skip to content

Commit 9f4d1f3

Browse files
wmudgejimright
andauthored
Local development environments (#35)
* Add playbook to construct a local development environment * Add updates for Ubuntu * Fix errant task entry * Add check for virtual environment activation and clean up instructions * Add section for local development setup and use * Update documentation for clarity, spelling, and a note about the default branch for the cloned projects. * Add package install for Ubuntu-based local development environment * Change with_items to loop * Add check to see if packages are installed Signed-off-by: Webster Mudge <[email protected]> Co-authored-by: Jim Enright <[email protected]>
1 parent 0488486 commit 9f4d1f3

File tree

2 files changed

+348
-21
lines changed

2 files changed

+348
-21
lines changed

README.adoc

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
11
# Cloudera Labs Ansible-Runner
22

3-
Readme last updated: 2021-03-17
3+
Readme last updated: 2022-02-09
44

5-
A Container image for running Ansible Playbooks and other common tools used with Cloudera Software on various Infrastructure Platforms. +
5+
A Container image for running Ansible Playbooks and other common tools used with Cloudera Software on various Infrastructure Platforms.
66

77
## Introduction
88

9-
This image attempts to resolve common dependencies for a broad range of full-service deployments of Cloudera Software, covering depdencies on infrastructure creation, platform deployment, and other configuration considerations, in the convenient package of a single large container. +
10-
This is useful when your playbooks may need to use a combination of CLI, Collection, Role, Python, and other commands in order to achieve your outcomes - while it may be possible or preferential for these to be deployed separately we find a single integrated container moderately convenient for local development. +
9+
This image attempts to resolve common dependencies for a broad range of full-service deployments of Cloudera Software, covering dependencies on infrastructure creation, platform deployment, and other configuration considerations, in the convenient package of a single large container.
10+
11+
This is useful when your playbooks may need to use a combination of CLI, Collection, Role, Python, and other commands in order to achieve your outcomes - while it may be possible or preferential for these to be deployed separately we find a single integrated container moderately convenient for local development.
12+
1113
It is based on the RedHat Ansible Runner, which provides a useful set of execution options including shell, direct container, and python import suitable for a variety of uses.
1214

1315
## Versions
14-
Upstream container is `quay.io/ansible/ansible-runner:stable-2.10-devel` +
16+
17+
Upstream container is `quay.io/ansible/ansible-runner:stable-2.10-devel`
18+
1519
This provides Ansible as `2.10` and Python as `3.8`
1620

1721
There are several switches within the Dockerfile to provide build output options for the user.
18-
Primarily these are to allow pruned images for working with each of the different usual Public cloud providers, or solely with CDP. The github actions builder runs on each release to produce example images you may use directly, or examine the Dockerfile to modify and build your own variant. +
22+
Primarily these are to allow pruned images for working with each of the different usual Public cloud providers, or solely with CDP. The github actions builder runs on each release to produce example images you may use directly, or examine the Dockerfile to modify and build your own variant.
1923

2024
Currently we provide the convenience builds: `base` `full` `aws` `azure` `gcp` +
2125
They may be found on the https://github.com/orgs/cloudera-labs/packages/container/package/cldr-runner[Github Package Repository]
2226

2327
## Usage
2428

2529
### Dockerfile
26-
The Dockerfile depends on deps-ansible.yml and deps-python.yml, and may be used directly to produce an image or for other purposes. +
30+
The Dockerfile depends on deps-ansible.yml and deps-python.yml, and may be used directly to produce an image or for other purposes.
31+
2732
For simplicity, you may wish to append your additional Ansible and Python deps to these files locally before building.
2833

2934
### common.sh
3035
This file sets the default names and variables used such as the image tag and container name, and hosts several shared convenience functions. It is not expected to be executed directly, but to serve as a central point to configure these values.
3136

3237
### build.sh
33-
Arguments: None +
34-
This is a convenience script to build the image locally and tag it as `cldr-runner:latest` by default. +
35-
It will stop and remove any currently running instances of the named container. +
38+
39+
_Arguments: None_ +
40+
This is a convenience script to build the image locally and tag it as `cldr-runner:latest` by default. It will stop and remove any currently running instances of the named container.
41+
3642
The image is approx ~2GB when fully constructed, which is why we have opted not to host it prebuilt at this time.
3743

3844
### run_project.sh
@@ -44,30 +50,77 @@ This is a convenience script to complete the following actions:
4450
* Use the first argument provided as the project dir within the container as `/runner/project`, consistent with Ansible-Runner practices
4551
* At this point it branches; either it will execute arbitrary commands and exit if they are passed in additionally to the project_dir, or it will enter a shell by default if no other arguments are passed
4652
47-
*Examples:* +
48-
`./run_project.sh /path/to/PycharmProjects` +
49-
This would launch the container with PycharmProjects mounted in /runner/project within the container, and drop the user in a container shell with all tools available along with their various host machine user profile directories mounted. +
53+
#### Examples
54+
```bash
55+
./run_project.sh /path/to/PycharmProjects
56+
```
57+
This would launch the container with `PycharmProjects` mounted in `/runner/project` within the container, and drop the user in a container shell with all tools available along with their various host machine user profile directories mounted.
58+
5059
This is an excellent environment in which to manage your various cloud credentials without resolving dependencies on your host machine, or interactively install further dependencies, or execute playbooks, etc.
5160

52-
`./run_project.sh /path/to/myProject ansible-runner run -p site.yml /runner -vv` +
53-
This would launch ansible-runner with the full path to myProject in /runner/project within the container. It would automatically execute ansible-runner with the playbook site.yml with /runner as the working directory and verbosity at 2v's, and then return to the host shell when complete. +
61+
```bash
62+
./run_project.sh /path/to/myProject ansible-runner run -p site.yml /runner -vv
63+
```
64+
This would launch `ansible-runner` with the full path to `myProject` in `/runner/project` within the container. It would automatically execute `ansible-runner` with the playbook `site.yml` with `/runner` as the working directory and verbosity at `2v` 's, and then return to the host shell when complete.
65+
5466
This is an excellent shortcut to scripted execution where the user has already set up various profiles.
5567
5668
### Other Considerations
57-
ansible.cfg is configured to set long timeouts, currently based on the longest running CDP Public Canary job at 150mins
58-
ansible.cfg also adds the path /runner/project/collections as a root for Ansible Collections, so if you happen to have your collections under development in this path (strongly recommended) they will be automatically discovered by the container alongside collections in the default paths.
69+
70+
`ansible.cfg` is configured to set long timeouts, currently based on the longest running CDP Public Canary job at 150mins. `ansible.cfg` also adds the path `/runner/project/collections` as a root for Ansible Collections, so if you happen to have your collections under development in this path (strongly recommended) they will be automatically discovered by the container alongside collections in the default paths.
5971
6072
### Limitations
61-
We do not currently bring logs and build artifacts back to the host machine before stopping or removing the container, you should retrieve any artifacts you want to keep at the end of your session.
6273
74+
We do not currently bring logs and build artifacts back to the host machine before stopping or removing the container, you should retrieve any artifacts you want to keep at the end of your session.
6375
6476
## Included Components
6577
66-
Please see included files under ./deps
78+
Please see included files under `./deps`.
79+
80+
## Local Development
81+
82+
The `cldr-runner` project can also be used to bootstrap a local development environment on the native host environment (as opposed to a Docker image). This option is more involved, but can avoid issues with Docker, such as mount latencies, and improve collection development.
83+
84+
The `local_environment.yml` playbook sets up a `cldr-runner`-like workspace for OSX and Ubuntu. The playbook will clone the Cloudera collections and `cdpy` for local work, install the external Ansible dependencies, update the Python `venv`, and create a convenient setup script for future work.
85+
86+
NOTE: The cloned Cloudera collections and cdpy project use the `main` branches by default. Manipulating the branches, etc. is outside the scope of the `local_environment.yml` playbook.
87+
88+
Development in this manner starts with sourcing the setup script, activating the virtual environment, and then switching to and running `cldr-runner`-based applications, such as `cloudera-deploy`, within their own projects while using the development environment's collections and tools.
89+
90+
You can change the execution environment by updating the Git-backed projects within the `ansible_collections` directory of the development environment or wholesale by changing the virtual environment and/or pointing to other development environments via the Ansible collection and role paths (see the setup scripts for details).
91+
92+
*Follow these steps to set up a local environment:*
93+
94+
Create a new virtual environment (using your favorite `venv` app):
95+
```bash
96+
$ mkvirtualenv <your development directory>
97+
```
98+
99+
Set up the bootstrap requirements:
100+
```bash
101+
$ export ANSIBLE_COLLECTIONS_PATH=<your target development directory>
102+
$ pip install ansible-base==2.10.16
103+
$ ansible-galaxy collection install community.general
104+
```
105+
106+
Make sure you are able to connect to public GitHub via SSH and then construct the development environment:
107+
```bash
108+
$ ansible-playbook local_development.yml
109+
```
110+
111+
NOTE: For Ubuntu deployments, you will need to add the `--ask-become-pass` flag.
112+
113+
Source the `setup-ansible-env.sh` file to use this development environment.
114+
```bash
115+
$ source <your development directory>/setup-ansible-env.sh
116+
```
67117
68118
## Developers
69-
Note that sequencing and dependency changes should be annotated in comments as to _why_ that change is considered necessary. +
70-
Currently the file trades off duplication and therefore size-on-disk in order to maintain easy compatibility between components with conflicting versions. Examples of this include Azure CLI and Azure Collection requiring different Azure Python library versions, or CDP CLI tending to trail Azure on the shared but version-pinned Colorama dependency. +
119+
120+
Note that sequencing and dependency changes should be annotated in comments as to _why_ that change is considered necessary.
121+
122+
Currently the file trades off duplication and therefore size-on-disk in order to maintain easy compatibility between components with conflicting versions. Examples of this include Azure CLI and Azure Collection requiring different Azure Python library versions, or CDP CLI tending to trail Azure on the shared but version-pinned Colorama dependency.
123+
71124
Where conflict arises, the Ansible Collection dependencies are installed to the system python environment, and the CLIs are installed to virtualenvs using pipx.
72125
73126
## Contributing

0 commit comments

Comments
 (0)