forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovisioning.yml
171 lines (138 loc) · 4.34 KB
/
provisioning.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
---
- hosts: localhost
connection: local
tasks:
#It will generate a file for each host with its number, it is needed for iterating over hosts and running iroha
# with different keys
- name: Create Variable File for Each host
template: src=template.yml.j2 dest=host_vars/{{ item.1 }}
with_indexed_items: "{{ groups['hosts'] }}"
- hosts: hosts
vars:
user: iroha #your user on the remote machine
tmp: "{{9999999 | random | to_uuid }}"
postgres_host: iroha_postgres
postgres_user: iroha
postgres_port: 5432
redis_host: iroha_redis
redis_port: 6379
IROHA_HOME: '{{playbook_dir}}/../../'
pre_tasks:
- name: Load Host Specific Generated Variables
include_vars: host_vars/{{ inventory_hostname }}
tasks:
- name: Set postgres password
set_fact:
postgres_passwd: '{{ tmp[:32] }}'
- name: Test if docker is installed
command: docker --version
register: docker_exists
failed_when: false
- name: Download docker installation script
get_url:
url: https://get.docker.com
dest: /tmp/script.sh
mode: 0755
validate_certs: false
when: docker_exists.rc|int > 0
- name: Install docker using downloaded script
shell: /tmp/script.sh
args:
chdir: /tmp
when: docker_exists.rc|int > 0
- name: Add usermod to run docker from {{ user }} user
command: usermod -aG docker {{user}}
become: yes
- name: Reconnect to use Docker as {{ user }}
shell: sleep 1; pkill -u {{ ansible_ssh_user }} sshd
async: 3
poll: 2
- name: Make sure docker is running
service: name=docker state=started
become: yes
- name: Write env file
blockinfile:
dest: "{{ ansible_env.HOME }}/.bashrc.d"
block: |
export POSTGRES_HOST={{ postgres_host }}
export POSTGRES_PORT={{ postgres_port }}
export POSTGRES_PASSWORD={{ postgres_passwd }}
export POSTGRES_USER={{ postgres_user }}
export REDIS_HOST={{ redis_host }}
export REDIS_PORT={{ redis_port }}
insertbefore: BOF
create: yes
- name: Install python-pip
package:
update_cache: yes
name: python-pip
state: present
become: yes
- name: Install py-docker
pip:
name: docker
become: yes
- name: Setup iroha docker network
docker_network:
name: iroha_network
- name: Run postgres in docker
docker_container:
name: iroha_postgres
image: postgres:9.5
state: started
recreate: yes
restart: yes
env:
POSTGRES_USER: '{{ postgres_user }}'
POSTGRES_PASSWORD: '{{ postgres_passwd }}'
networks:
- name: iroha_network
- name: Run redis in docker
docker_container:
name: iroha_redis
image: redis:3.2.8
state: started
recreate: yes
restart: yes
networks:
- name: iroha_network
- name: Make data dir
file:
path: '{{ansible_env.HOME}}/iroha_data'
state: directory
mode: 0755
owner: '{{ user }}'
become: yes
- name: Copy peers list
copy:
src: '{{playbook_dir}}/data/peers.list'
dest: '{{ansible_env.HOME}}/iroha_data/peers.list'
- name: Copy config generator
copy:
src: '{{playbook_dir}}/generate_config.py'
dest: '{{ansible_env.HOME}}/iroha_data/generate_config.py'
- name: Generate config
command: python3 '{{ansible_env.HOME}}'/iroha_data/generate_config.py -p '{{ postgres_passwd }}' -u '{{ postgres_user }}'
- name: Run iroha in docker
docker_container:
name: iroha
image: hyperledger/iroha-docker:develop
state: started
restart: yes
recreate: yes
pull: yes
ports:
- "50051:50051"
- "10001:10001"
networks:
- name: iroha_network
volumes:
- '{{ansible_env.HOME}}/iroha_data:/opt/iroha_data'
env:
POSTGRES_HOST: '{{ postgres_host }}'
POSTGRES_PORT: '{{ postgres_port }}'
POSTGRES_PASSWORD: '{{ postgres_passwd }}'
POSTGRES_USER: '{{ postgres_user }}'
REDIS_HOST: '{{ redis_host }}'
REDIS_PORT: '{{ redis_port }}'
KEY: node{{ key }}