From a9dac00e49f09691fba2eece9912cdd06a8f9108 Mon Sep 17 00:00:00 2001 From: rohan47 Date: Sun, 14 Oct 2018 23:03:59 +0530 Subject: [PATCH] Added ansible playbook to generate setup-profile Signed-off-by: rohan47 --- .../ansible-setup-profile/README.md | 37 +++++++++++++++++ .../ansible-setup-profile/configure.yml | 18 ++++++++ .../setup-profile/group_vars/all | 16 ++++++++ .../templates/client_public.j2 | 3 ++ .../templates/exportenv.yml.j2 | 41 +++++++++++++++++++ .../templates/inventory.ini.j2 | 23 +++++++++++ .../templates/server_public.j2 | 8 ++++ .../templates/systems.yml.j2 | 11 +++++ 8 files changed, 157 insertions(+) create mode 100644 setup-profiles/ansible-setup-profile/README.md create mode 100644 setup-profiles/ansible-setup-profile/configure.yml create mode 100755 setup-profiles/ansible-setup-profile/setup-profile/group_vars/all create mode 100644 setup-profiles/ansible-setup-profile/templates/client_public.j2 create mode 100644 setup-profiles/ansible-setup-profile/templates/exportenv.yml.j2 create mode 100755 setup-profiles/ansible-setup-profile/templates/inventory.ini.j2 create mode 100644 setup-profiles/ansible-setup-profile/templates/server_public.j2 create mode 100644 setup-profiles/ansible-setup-profile/templates/systems.yml.j2 diff --git a/setup-profiles/ansible-setup-profile/README.md b/setup-profiles/ansible-setup-profile/README.md new file mode 100644 index 0000000..0438a30 --- /dev/null +++ b/setup-profiles/ansible-setup-profile/README.md @@ -0,0 +1,37 @@ +# Ansible setup-profile +Ansible playbook to generate setup-profile for [gbench](https://github.com/gluster/gbench/) using jinja2 template. + +## How to run? + +Run the playbook `configure.yml` with additional parameters for servers, clients and devices. Where servers are list of coma seperated hosts(IP addresses/hostnames) that are going to be glusterfs server, clients are coma seperated clients(IP addresses/hosts) that are going to be gluster clients and devices are the list of coma seperated drives(currently same devices names are considered) that are attached to the servers. + +```console +ansible-playbook configure.yml -e 'servers=host1,host2,...hostn clients=client1,client2,...clientn devices=sda,sdb' +``` + +## What `configure.yml` does? +`configure.yml` takes the aditional facts and use it to generate another yaml file `exportenv.yml` using jinja template and `systems.yml` which stores server and client IP/hostname and then it includes the generated `exportenv.yml` and runs its tasks. + +`exportenv.yml` creates directories for server and client and adds public files in those created directories. + +For example there are three servers whose IP addresses are `10.0.0.1`, `10.0.0.2` and `10.0.0.3` and two clients `10.0.0.4` and `10.0.0.5` the generated directory structure will look like the following which is according to the desired setup-profile +```console +ansible-playbook configure.yml -e 'servers=10.0.0.1,10.0.0.2,10.0.0.3 clients=10.0.0.4,10.0.0.5 devices=sda,sdb,sdc' +``` + +``` +setup-profile +├── group_vars +│   ├── all +│   ├── client1 +│   │   └── public +│   ├── client2 +│   │   └── public +│   ├── server1 +│   │   └── public +│   ├── server2 +│   │   └── public +│   └── server3 +│   └── public +└── inventory.ini +``` diff --git a/setup-profiles/ansible-setup-profile/configure.yml b/setup-profiles/ansible-setup-profile/configure.yml new file mode 100644 index 0000000..235c40e --- /dev/null +++ b/setup-profiles/ansible-setup-profile/configure.yml @@ -0,0 +1,18 @@ +--- +- hosts: localhost + tasks: + + # Create exportenv.yml from the src jinja2 file + - template: + src: templates/exportenv.yml.j2 + dest: exportenv.yml + + # Create systems file containing servers and clients from the src jinja2 file + - template: + src: templates/systems.yml.j2 + dest: systems.yml + + # includes the tasks from exportenv.yml which was created above + - include: exportenv.yml +... + diff --git a/setup-profiles/ansible-setup-profile/setup-profile/group_vars/all b/setup-profiles/ansible-setup-profile/setup-profile/group_vars/all new file mode 100755 index 0000000..b897e4c --- /dev/null +++ b/setup-profiles/ansible-setup-profile/setup-profile/group_vars/all @@ -0,0 +1,16 @@ +--- +# Common variables for all hosts + +ansible_connection: ssh +ansible_user: root + +# Cleanup of devices is allowed on this setup +gbench_device_cleanup: yes + +gbench_client_mountpoint: "/mnt/gbench/" +# Infiniband (IB) over IP variables +#ipoib_device: ib0 +#ipoib_netmask: 255.255.255.0 +#ipoib_use_gateway: yes +#ipoib_gateway: em1 + diff --git a/setup-profiles/ansible-setup-profile/templates/client_public.j2 b/setup-profiles/ansible-setup-profile/templates/client_public.j2 new file mode 100644 index 0000000..37a5987 --- /dev/null +++ b/setup-profiles/ansible-setup-profile/templates/client_public.j2 @@ -0,0 +1,3 @@ +--- +glusterip: {{ hostvars[inventory_hostname]['client%s' | format(var)] }} + diff --git a/setup-profiles/ansible-setup-profile/templates/exportenv.yml.j2 b/setup-profiles/ansible-setup-profile/templates/exportenv.yml.j2 new file mode 100644 index 0000000..fde5cd4 --- /dev/null +++ b/setup-profiles/ansible-setup-profile/templates/exportenv.yml.j2 @@ -0,0 +1,41 @@ +--- + - include_vars: systems.yml + + - template: + src: templates/inventory.ini.j2 + dest: setup-profile/inventory.ini + +# Create directory for servers and copy public file with value set to server ip/hostname +{% for server in servers.split(',') %} +{% set var = loop.index %} + - file: + path: setup-profile/group_vars/server{{ loop.index }} + state: directory + + - name: server{{ var }} + template: + src: templates/server_public.j2 + dest: setup-profile/group_vars/server{{ var }}/public + vars: + var: {{ var }} + +{% endfor %} + +# Create directory for clients and copy public file with value set to client ip/hostname +{% for client in clients.split(',') %} +{% set var = loop.index %} + - file: + path: setup-profile/group_vars/client{{ loop.index }} + state: directory + + - name: client{{ var }} + template: + src: templates/client_public.j2 + dest: setup-profile/group_vars/client{{ var }}/public + vars: + var: {{ var }} + +{% endfor %} + +... + diff --git a/setup-profiles/ansible-setup-profile/templates/inventory.ini.j2 b/setup-profiles/ansible-setup-profile/templates/inventory.ini.j2 new file mode 100755 index 0000000..0491499 --- /dev/null +++ b/setup-profiles/ansible-setup-profile/templates/inventory.ini.j2 @@ -0,0 +1,23 @@ +[servers] +{% for host in servers.split(',') %} +{{ host }} +{% endfor %} + +[clients] +{% for host in clients.split(',') %} +{{ host }} +{% endfor %} + +{% for server in servers.split(',') %} +[server{{ loop.index }}] +{{ server }} + +{% endfor %} + +{% for client in clients.split(',') %} +[client{{ loop.index }}] +{{ client }} + +{% endfor %} + + diff --git a/setup-profiles/ansible-setup-profile/templates/server_public.j2 b/setup-profiles/ansible-setup-profile/templates/server_public.j2 new file mode 100644 index 0000000..2a46fdf --- /dev/null +++ b/setup-profiles/ansible-setup-profile/templates/server_public.j2 @@ -0,0 +1,8 @@ +--- +glusterip: {{ hostvars[inventory_hostname]['server%s' | format(var)] }} + +devices: +# Generate list of drives +{% for device in devices.split(',') %} + - '/dev/{{ device }}' +{% endfor %} diff --git a/setup-profiles/ansible-setup-profile/templates/systems.yml.j2 b/setup-profiles/ansible-setup-profile/templates/systems.yml.j2 new file mode 100644 index 0000000..86728e8 --- /dev/null +++ b/setup-profiles/ansible-setup-profile/templates/systems.yml.j2 @@ -0,0 +1,11 @@ +--- +servers: {{ servers }} +clients: {{ clients }} + +{% for server in servers.split(',') %} +server{{ loop.index }}: {{ server }} +{% endfor %} + +{% for client in clients.split(',') %} +client{{ loop.index }}: {{ client }} +{% endfor %}