diff --git a/src/agent/ansible/roles/upgrade_compose/composerupgrade/tasks/apply.yml b/src/agent/ansible/roles/upgrade_compose/composerupgrade/tasks/apply.yml new file mode 100755 index 000000000..acbb1533e --- /dev/null +++ b/src/agent/ansible/roles/upgrade_compose/composerupgrade/tasks/apply.yml @@ -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" + diff --git a/src/agent/ansible/roles/upgrade_compose/plays.yml b/src/agent/ansible/roles/upgrade_compose/plays.yml new file mode 100755 index 000000000..2271441fc --- /dev/null +++ b/src/agent/ansible/roles/upgrade_compose/plays.yml @@ -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" \ No newline at end of file diff --git a/src/agent/ansible/upgradecomposer.yml b/src/agent/ansible/upgradecomposer.yml new file mode 100755 index 000000000..364f091ce --- /dev/null +++ b/src/agent/ansible/upgradecomposer.yml @@ -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 }}