Skip to content

Instantly share code, notes, and snippets.

@bhalothia
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bhalothia/eddf783affeed62d9c03 to your computer and use it in GitHub Desktop.
Save bhalothia/eddf783affeed62d9c03 to your computer and use it in GitHub Desktop.
register variables across plays
- vars:
# Extra vars from Rundeck for partition type
partition: "{{ partition }}"
# For 'nmctl ps' wrapper - Some deployment validation
number_of_tries: 5
sleep_between_tries: 60
hosts: "app-{{ partition }}[0]" # Canary
tags:
- "canary"
tasks:
- name: "Grab the target app version set in the environment"
shell: "knife environment show {{ chef_environment.stdout }} -c /etc/chef/client.rb -a default_attributes.app.install_build_version | grep version | awk '{ print $2 }'"
register: "target_app_build"
changed_when: False
tags:
- "version_check"
- "upgrade_type"
- name: "Find the app version running on the canary"
command: "cat /home/app/builds/{{ app_branch.stdout }}/installed_app_version"
register: "actual_app_build"
changed_when: False
tags:
- "version_check"
- "upgrade_type"
- name: "Setting up as fact target build"
set_fact:
target_app_build: "{{ target_app_build.stdout }}"
- name: "Setting up as fact actual build"
set_fact:
actual_app_build: "{{ actual_app_build.stdout }}"
- hosts: "app-{{ partition }}"
tasks:
- name: "Performing upgrade: Running Chef client"
command: "chef-client"
tags:
- "app_upgrade"
- "upgrade"
- hosts: "no-app-{{ partition }}"
tasks:
- name: "Performing upgrade: Running Chef client"
command: "date"
when: "{{ hostvars[groups['app-a1'][0]]['target_app_build'] }} != {{ hostvars[groups['app-a1'][0]]['actual_app_build'] }}"
tags:
- "no_app_upgrade"
- "upgrade"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment