Skip to content

Commit

Permalink
Adding feature : auto-generated inventory file
Browse files Browse the repository at this point in the history
  • Loading branch information
sunggun-yu committed Feb 24, 2018
1 parent 0d6fc53 commit a7e74b4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
@@ -1,7 +1,7 @@
openstack-bootstrap
===================

Create OpenStack instances and volume. also, attach and mount the volumes to the instances.
Create OpenStack instances and volume. and, attach and mount the volumes to the instances. It also generates the Ansible inventory file automatically as a result.

Requirements
------------
Expand Down Expand Up @@ -83,6 +83,21 @@ openstack_bootstrap_specs:
path: /path/mount/02
```


This role also generates the inventory file automatically under `inventory_dir`

```yaml
openstack_bootstrap_inventory:
filename: os_inventory.ini
force: yes
backup: no
```

- `filename` : The auto-generated inventory file name.
- `force` : It will overwrites the file if it is `yes`.
- `backup` : It will create backup file if it is `yes`.


Dependencies
------------

Expand Down
5 changes: 5 additions & 0 deletions defaults/main.yml
@@ -1,6 +1,11 @@
---
# defaults file for openstack-bootstrap

openstack_bootstrap_inventory:
filename: os_inventory.ini
force: yes
backup: no

openstack_bootstrap_specs:
- name: instance-name-01
ansible:
Expand Down
15 changes: 15 additions & 0 deletions tasks/inventory.yml
@@ -0,0 +1,15 @@
---

# ----------------------------------------------------------------------------------------------------------------------
# Generate the inventory file
# ----------------------------------------------------------------------------------------------------------------------

- name: "Generate the inventory file"
delegate_to: localhost
template:
src: os_inventory.ini.j2
dest: "{{ inventory_dir }}/{{ openstack_bootstrap_inventory.filename | default('os_inventory.ini') }}"
force: "{{ openstack_bootstrap_inventory.force | default(yes) }}"
backup: "{{ openstack_bootstrap_inventory.backup | default(no) }}"
tags:
- inventory
2 changes: 2 additions & 0 deletions tasks/main.yml
Expand Up @@ -7,3 +7,5 @@
loop_control:
loop_var: openstack_bootstrap_spec

- name: "Generate the inventory file from result of openstack_bootstrap_specs"
include_tasks: inventory.yml
17 changes: 17 additions & 0 deletions templates/os_inventory.ini.j2
@@ -0,0 +1,17 @@
# Generated inventory file by openstack-bootstrap

{% for os_group_name, os_hosts in groups.iteritems() %}
{% if 'ungrouped' != os_group_name %}
[{{ os_group_name }}]
{% for os_host_name in os_hosts %}
{% if 'localhost' != os_host_name %}
{% if 'all' == os_group_name %}
{{ os_host_name }} ansible_host={{ hostvars[os_host_name].ansible_host }}
{% else %}
{{ os_host_name }}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}

{% endfor %}

0 comments on commit a7e74b4

Please sign in to comment.