Skip to content

Commit

Permalink
Add a mechanism to load environment variables and files that are spec…
Browse files Browse the repository at this point in the history
…ific to the loaded cluster_vars. Useful, for example, for loading bastion SSH keys and ansible SSH parameters at runtime.
  • Loading branch information
Dougal Seeley committed Jan 17, 2021
1 parent e8cb0e9 commit d954383
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions EXAMPLE/cluster.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
---

- name: clusterverse | Set up the environment
hosts: localhost:all
connection: local
gather_facts: no
tasks:
- { import_role: { name: 'clusterverse/_dependencies' }, tags: ["clusterverse_environment"] }
- { name: "clusterverse | Set env vars", set_fact: { envvars: "{{ cluster_vars.env_setup.vars | default({}) }}" }, tags: ["clusterverse_environment"] }
- { name: "clusterverse | Copy env files", local_action: "copy content={{item.value}} dest={{item.key}}", with_dict: "{{ cluster_vars.env_setup.files | ternary(cluster_vars.env_setup.files, {}) }}", run_once: yes, tags: ["clusterverse_environment"] }

- name: clusterverse | Deploy the cluster
hosts: localhost
connection: local
gather_facts: no
environment: "{{envvars}}"
tasks:
- { name: "Get dependent roles via ansible-galaxy", local_action: "command ansible-galaxy install -fr requirements.yml", tags: ["always"] }

Expand All @@ -14,20 +24,24 @@
- name: clusterverse | Wait for SSH connections
hosts: all
gather_facts: no
environment: "{{envvars}}"
tasks: [ {wait_for_connection: "", tags: ["always"] } ]

- name: clusterverse | Configure the cluster
hosts: all
environment: "{{envvars}}"
tasks: [ { include_role: { name: "clusterverse/config", apply: { tags: ["clusterverse_config"]} }, tags: ["clusterverse_config"] } ]

## Application roles
- name: Application roles
hosts: all
environment: "{{envvars}}"
tasks:
- { include_role: { name: "testrole", apply: { tags: ["testrole"]} }, tags: ["testrole"] }
##

- name: clusterverse | Perform cluster readiness operations
hosts: localhost
connection: local
environment: "{{envvars}}"
tasks: [ { include_role: { name: "clusterverse/readiness", apply: { tags: ["clusterverse_readiness"]} }, tags: ["clusterverse_readiness"] } ]
8 changes: 8 additions & 0 deletions EXAMPLE/cluster_defs/aws/cluster_vars.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
---

cluster_vars:
# env_setup:
# vars:
# ANSIBLE_SSH_ARGS: '-o UserKnownHostsFile=/dev/null -o ControlMaster=auto -o ControlPersist=60s -o ProxyCommand="ssh -i ./id_rsa_bastion -W %h:%p -q [email protected]"'
# files:
# id_rsa_bastion: |
# -----BEGIN RSA PRIVATE KEY-----
# M8fBuCjd/wbIi8uDGMGe8ezJKgIBAA3UNuiXK1H3DCXaCCA5QmASFhQhUlgIIEAv
-----END RSA PRIVATE KEY-----
dns_cloud_internal_domain: "{{region}}.compute.internal" # The cloud-internal zone as defined by the cloud provider (e.g. GCP, AWS)
dns_nameserver_zone: &dns_nameserver_zone "" # The zone that dns_server will operate on. gcloud dns needs a trailing '.'. Leave blank if no external DNS (use IPs only)
dns_server: "" # Specify DNS server. nsupdate, route53 or clouddns. If empty string is specified, no DNS will be added.
Expand Down
8 changes: 8 additions & 0 deletions EXAMPLE/cluster_defs/gcp/cluster_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ _ubuntu2004image: "projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v202
_centos7image: "projects/centos-cloud/global/images/centos-7-v20201216"

cluster_vars:
# env_setup:
# vars:
# ANSIBLE_SSH_ARGS: '-o UserKnownHostsFile=/dev/null -o ControlMaster=auto -o ControlPersist=60s -o ProxyCommand="ssh -i ./id_rsa_bastion -W %h:%p -q [email protected]"'
# files:
# id_rsa_bastion: |
# -----BEGIN RSA PRIVATE KEY-----
# M8fBuCjd/wbIi8uDGMGe8ezJKgIBAA3UNuiXK1H3DCXaCCA5QmASFhQhUlgIIEAv
# -----END RSA PRIVATE KEY-----
image: "{{_ubuntu2004image}}"
dns_cloud_internal_domain: "c.{{ (_service_account_rawtext | string | from_json).project_id }}.internal" # The cloud-internal zone as defined by the cloud provider (e.g. GCP, AWS)
dns_nameserver_zone: &dns_nameserver_zone "zepkey.com." # The zone that dns_server will operate on. gcloud dns needs a trailing '.'. Leave blank if no external DNS (use IPs only)
Expand Down
2 changes: 1 addition & 1 deletion EXAMPLE/jenkinsfiles/Jenkinsfile_ops
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ node {

sh 'ls -l'
println("currentBuild.getBuildCauses: " + currentBuild.getBuildCauses())
if (currentBuild.getBuildCauses('hudson.model.Cause$SCMTriggerCause').size() > 0) {
if (currentBuild.getBuildCauses('hudson.model.Cause$SCMTriggerCause').size() > 0 || currentBuild.getBuildCauses('hudson.model.Cause$UpstreamCause').size() > 0) {
println("Checking out default scm: " + scm.userRemoteConfigs + " -- " + scm.branches)
checkout(scm)
} else {
Expand Down

0 comments on commit d954383

Please sign in to comment.