sky-uk/clusterverse

Redeploy: extra variables passed to sub shell

flfernandez opened this issue · 3 comments

Due to how Redeploy invokes the cluster.yml using a sub shell, there is currently no way to pass variables to the cluster.yml , so for example it could differentiate between a standard run and a redeployment run.

So my suggestion is to have an extra dictionary variable passed (redeploy_extra_vars) on all redeployment methods to the sub shell invoking cluster.yml

Example

  • redeploy.yml playbook:
- name: Redeploy
  hosts: localhost
  connection: local
  tasks:
    - name: Run redeploy
      include_role:
        name: clusterverse/redeploy
      vars:
        mainclusteryml: "cluster.yml"
        predeleterole: "persistence-cassandra/redeploy"
        redeploy_extra_vars:
          cassandra_redeploy: True
- name: "Run {{mainclusteryml}} to add {{cluster_host_redeploying.hostname}} to cluster"
  shell: "{{ (argv | join(' ')) | regex_replace('redeploy.yml', mainclusteryml) }} -e '{'redeploy_extra_vars': {{redeploy_extra_vars|default({})|to_json}}}' -e cluster_suffix={{cluster_suffix}} -e '{'cluster_hosts_target': [{{cluster_host_redeploying | to_json}}]}'"
  register: r__mainclusteryml
  no_log: True
  ignore_errors: yes
- name: "by_hosttype_by_host | Run {{mainclusteryml}} to add {{host_to_redeploy.hostname}} to cluster"
  shell: "{{ (argv | join(' ')) | regex_replace('redeploy.yml', mainclusteryml) }} -e '{'redeploy_extra_vars': {{redeploy_extra_vars|default({})|to_json}}}' -e cluster_suffix={{cluster_suffix}} -e '{'cluster_hosts_target': [{{host_to_redeploy | to_json}}]}'"
  register: r__mainclusteryml
  no_log: True
  ignore_errors: yes
- name: "Run {{mainclusteryml}} to fix cluster"
  shell: "{{ (argv | join(' ')) | regex_replace('redeploy.yml', mainclusteryml) -e '{'redeploy_extra_vars': {{redeploy_extra_vars|default({})|to_json}}}'}}"
  register: r__mainclusteryml
  no_log: True
  ignore_errors: yes

The arguments from the root shell are passed to the cluster.yml sub-shell. You should be able to do e.g.:

ansible-playbook redeploy.yml -e buildenv=sandbox -e clusterid=test -e cloud_type=gcp -e region=europe-west1 -e canary=none -e cassandra_redeploy=True

Thanks. I understand it could be passed via the command line, but my ask is to not having to do this, and pass arguments via the playbook (redeploy.yml) instead. Passing via command line requires that the arguments are known at the time of the execution.
Because it is a sub-shell, it would be very useful to allow multiple arguments to be passed - otherwise the only way is the command line.

closed by #104