-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add inventory-generator under new sub pkg
- Loading branch information
1 parent
a00df57
commit a705552
Showing
4 changed files
with
508 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
Dynamic Inventory Generation | ||
============================ | ||
|
||
Script within the openshift-ansible image that can dynamically | ||
generate an Ansible inventory file from an existing cluster. | ||
|
||
## Configure | ||
|
||
User configuration helps to provide additional details when creating an inventory file. | ||
The default location of this file is in `root/etc/inventory-generator-config.yaml`. The | ||
following configuration values are either expected or default to the given values when omitted: | ||
|
||
- `openshift_cluster_user`: | ||
- username of account capable of listing nodes in a cluster | ||
- used for querying the cluster using `oc` to retrieve additional node information. | ||
|
||
- `master_config_path`: | ||
- specifies where to look for the bind-mounted `master-config.yaml` file in the container | ||
- if omitted or a `null` value is given, its value is defaulted to `/opt/app-root/src/master-config.yaml` | ||
|
||
- `admin_kubeconfig_path`: | ||
- specifies where to look for the bind-mounted `admin.kubeconfig` file in the container | ||
- if omitted or a `null` value is given, its value is defaulted to `/opt/app-root/src/.kube/config` | ||
|
||
- `ansible_ssh_user`: | ||
- specifies the ssh user to be used by Ansible when running the specified `PLAYBOOK_FILE` (see `README_CONTAINER_IMAGE.md` for additional information on this environment variable). | ||
- if omitted, its value is defaulted to `root` | ||
|
||
- `ansible_become_user`: | ||
- specifies a user to "become" on the remote host. Used for privilege escalation. | ||
- If a non-null value is specified, `ansible_become` is implicitly set to `yes` in the resulting inventory file. | ||
|
||
See the supplied sample user configuration file in `root/etc/inventory-generator-config.yaml` for additional optional inventory variables that may be specified. | ||
|
||
## Build | ||
|
||
See `README_CONTAINER_IMAGE.md` for information on building this image. | ||
|
||
## Run | ||
|
||
Given a master node's `master-config.yaml` file, a user configuration file (see "Configure" section), and an `admin.kubeconfig` file, the command below will: | ||
|
||
1. Use `oc` to query the host about additional node information (using the supplied `kubeconfig` file and `openshift_cluster_user` value) | ||
2. Generate an inventory file based on information retrieved from `oc get nodes` and the given `master-config.yaml` file. | ||
3. run the specified [openshift-ansible](https://github.com/openshift/openshift-ansible) `health.yml` playbook using the generated inventory file from the previous step | ||
|
||
``` | ||
docker run -u `id -u` \ | ||
-v $HOME/.ssh/id_rsa:/opt/app-root/src/.ssh/id_rsa:Z,ro \ | ||
-v /tmp/origin/master/admin.kubeconfig:/opt/app-root/src/.kube/config:Z \ | ||
-v /tmp/origin/master/master-config.yaml:/opt/app-root/src/master-config.yaml:Z \ | ||
-e OPTS="-v --become-user root" \ | ||
-e PLAYBOOK_FILE=playbooks/byo/openshift-checks/health.yml \ | ||
-e GENERATE_INVENTORY=true \ | ||
-e USER=`whoami` \ | ||
openshift/origin-ansible | ||
``` | ||
|
||
**Note** In the command above, specifying the `GENERATE_INVENTORY` environment variable will automatically generate the inventory file in an expected location. | ||
An `INVENTORY_FILE` variable (or any other inventory location) does not need to be supplied when generating an inventory. | ||
|
||
## Debug | ||
|
||
To debug the `generate` script, run the above script interactively | ||
and manually execute `/usr/local/bin/generate`: | ||
|
||
``` | ||
... | ||
docker run -u `id -u` \ | ||
-v ... | ||
... | ||
-it openshift/origin-ansible /bin/bash | ||
--- | ||
bash-4.2$ cd $HOME | ||
bash-4.2$ ls | ||
master-config.yaml | ||
bash-4.2$ /usr/local/bin/generate $HOME/generated_hosts | ||
bash-4.2$ ls | ||
generated_hosts master-config.yaml | ||
bash-4.2$ less generated_hosts | ||
... | ||
``` | ||
|
||
## Notes | ||
|
||
See `README_CONTAINER_IMAGE.md` for additional information about this image. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
# meta config | ||
master_config_path: "/opt/app-root/src/master-config.yaml" | ||
admin_kubeconfig_path: "/opt/app-root/src/.kube/config" | ||
|
||
# default user configuration | ||
ansible_ssh_user: ec2-user | ||
ansible_become: "yes" | ||
ansible_become_user: "root" | ||
|
||
# openshift-ansible inventory vars | ||
openshift_uninstall_images: false | ||
openshift_install_examples: true | ||
openshift_deployment_type: origin | ||
|
||
openshift_release: 3.6 | ||
openshift_image_tag: v3.6.0 | ||
openshift_hosted_logging_deploy: null # defaults to "true" if loggingPublicURL is set in master-config.yaml | ||
openshift_logging_image_version: v3.6.0 | ||
openshift_disable_check: "" | ||
|
||
# openshift cluster-viewer info | ||
openshift_cluster_user: cluster-lister # name of user or service account able to list nodes in a cluster |
Oops, something went wrong.