Skip to content

Commit

Permalink
[CE-374] Ansible plays updating/redeploying BNA archive
Browse files Browse the repository at this point in the history
This patch adds onto the ansible agent plays. Specifically, it adds
upgradecomposer.yml, which invokes roles/upgrade_compose/plays.yml,
which invokes roles/upgrade_compose/composerupgrade/tasks/apply.yml
on the builder node. This uploads the bna in the secrets/networks
folder to the builder node then runs 'composer update' with the bna.

Change-Id: I7a579d0fa7d9fbde7f25730a4d5b9c3f65dae3b6
Signed-off-by: Jordan Dearsley <[email protected]>
  • Loading branch information
jordancde committed May 28, 2018
1 parent 88c7a6a commit c7dde0e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
- name: Setup and initialize variables
set_fact:
current_host: "{{ hostvars[inventory_hostname].inter_name }}"
peers: "{{ [] }}"

- name: Get peer container list
set_fact:
peers: |
{{ peers + [{'org':item.split('@')[1].split('.')[-1],
'name':item.split('@')[1] | replace('.', '-'),
'role':item.split('@')[0]}] }}
with_items: "{{ fabric.network[current_host].peers | default([]) }}"

- name: Setup few variables
set_fact:
fabricworkdir: "/opt/gopath/{{ env }}/fabric"
fabricpath: "/opt/gopath/{{ env }}/src/github.com/hyperledger/fabric"
gopath: "/opt/gopath/{{ env }}"
localhome: "/home/{{ fabric.ssh_user }}/.composer"
alladmin: ""
peerorgs: "{{ peers | map(attribute='org') | list | unique | sort }}"

- name: Generate all admin options
set_fact:
alladmin: "{{ alladmin + '-A ' + item + 'Admin -C /home/composer/.composer/' + item + 'Admin/admin-pub.pem ' }}"
with_items: "{{ peerorgs }}"
tags: "generatealladmin"

- name: Upload bna file
copy:
src: "{{ item }}"
dest: "{{ fabricworkdir }}/keyfiles/"
with_fileglob:
- "{{ playbook_dir }}/../../secrets/networks/*.bna"
tags: "uploadbna"

- name: Update bna on network
command: >-
docker run -v {{ localhome }}:/home/composer/.composer
-v {{ fabricworkdir }}:{{ fabricworkdir }}
hyperledger/composer-cli:next network update
-c {{ peerorgs[0] }}Admin@{{ networkname }}
-a {{ fabricworkdir }}/keyfiles/{{ networkname }}.bna
tags: "updatebna"

10 changes: 10 additions & 0 deletions src/agent/ansible/roles/upgrade_compose/plays.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: update bna and deploy
hosts: builders
gather_facts: true
user: "{{ fabric.ssh_user }}"
vars_files:
- "./../../vars/{{ env }}.yml"
tasks:
- include_tasks: "composerupgrade/tasks/apply.yml"
tags: "deploybna"
19 changes: 19 additions & 0 deletions src/agent/ansible/upgradecomposer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Get start timestamp
hosts: cloud
connection: local
tasks:
- set_fact:
starttime: "{{ ansible_date_time }}"

- name: Run the plays
include: "roles/upgrade_compose/plays.yml"

- name: inform the installer
hosts: cloud
connection: local
tasks:
- debug:
msg: >-
The work load started at {{ hostvars.cloud.starttime.time }},
ended at {{ ansible_date_time.time }}

0 comments on commit c7dde0e

Please sign in to comment.