Skip to content
Snippets Groups Projects
Commit 6bc615ba authored by Attila Farkas's avatar Attila Farkas
Browse files

add template user playbooks and roles

parent 9b180a03
No related branches found
No related tags found
1 merge request!7Resolve Refactoring
......@@ -16,6 +16,55 @@ def _create_inventory(input_definitions):
generate_file("provisioning/inventory.ini", output)
def _create_config(input_definitions, flags):
""" Creates a file with common variables for all roles. """
hosts = []
for host in input_definitions["hosts"]:
new_host = dict()
new_host["name"] = host["name"]
hosts.append(new_host)
routers = []
for router in input_definitions["routers"]:
new_router = dict()
new_router["name"] = router["name"]
routers.append(new_router)
config_template = load_template("config")
output = config_template.render(hosts=hosts, routers=routers)
generate_file("base_provisioning/config.yml", output)
def _create_config_playbooks(input_definitions, flags):
""" Generates playbooks and roles for basic device configuration. """
# TODO create playbooks
return
def _create_user_playbooks(input_definitions):
""" Generates template playbooks and roles for users. """
playbook_template = load_template("playbook")
generate_file("provisioning/playbook.yml", playbook_template.render())
user_hosts_template = load_template("user_hosts")
generate_file("provisioning/roles/hosts/tasks/main.yml", user_hosts_template.render())
user_routers_template = load_template("user_routers")
generate_file("provisioning/roles/routers/tasks/main.yml", user_routers_template.render())
user_host_template = load_template("user_separate_hosts")
for host in input_definitions["hosts"]:
output = user_host_template.render(host_name=host["name"])
generate_file("provisioning/roles/" + host["name"] + "/tasks/main.yml", output)
user_router_template = load_template("user_separate_routers")
for router in input_definitions["routers"]:
output = user_router_template.render(router_name=router["name"])
generate_file("provisioning/roles/" + router["name"] + "/tasks/main.yml", output)
def generate_playbooks(input_definitions, flags):
""" Generates ansible playbooks.
......@@ -24,3 +73,6 @@ def generate_playbooks(input_definitions, flags):
"""
_create_inventory(input_definitions)
_create_config(input_definitions, flags)
_create_config_playbooks(input_definitions, flags)
_create_user_playbooks(input_definitions)
hosts:
{% for host in hosts %}
- name: {{ host.name }}
{% endfor %}
routers:
{% for router in routers %}
- name: {{ router.name }}
{% endfor %}
......@@ -2,19 +2,23 @@
# Basic configuration of all defined devices
- name: Configuring all hosts
hosts: {{ hosts|map(attribute='host_name')|unique|join(',') }}
hosts: hosts
become: yes
roles:
- hosts
{% for host in hosts %}
- name: Configuring host {{ host.host_name }} separately
hosts: {{ host.host_name }}
- name: Configuring host {{ item.name }} separately
hosts: {{ item.name }}
become: yes
loop: "{{ hosts }}"
roles:
- {{ host.host_name }}
- {{ item.name }}
{# TODO finish playbook #}
{% endfor %}
{% for host in hosts %}
- name: Configuring host {{ host.host_name }}
hosts: {{ host.host_name }}
......
---
# Main user ansible playbook
# Main user ansible playbook.
# Write your custom configuration here:
- name: Hello world
......
---
# This is a role for all hosts.
# You can write your tasks here.
# These changes will affect all hosts.
......
---
# This is a role for all routers.
# You can write your tasks here.
...
---
# This is a role for the host {{ host_name }}.
# You can write your tasks here.
# These changes will affect only the host {{ host_name }}.
......
---
# This is a role for the router {{ router_name }}.
# You can write your tasks here.
...
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment