Migrate a tool from Salt to Ansible, is it possible and what can be done with Ansible ?

1,135 views
Skip to first unread message

oxed...@gmail.com

unread,
May 31, 2017, 8:34:36 AM5/31/17
to Ansible Project
Hello Ansible users,

I made a tool based on Salt Stack, a deployment tool like Ansible.

This tool, Banquise, is made to deploy groups of serveurs (clusters, HPC clusters) and groups of workstations.

Someone asked me if it would be possible to propose an Ansible version of this tool, but I don't master Ansible as Salt, so I would like to know if some things are possible in Ansible.

To understand the Banquise tool:

Basically, sys admin define it's nodes into files with the following structure: type > group > node.
For example, compute1 in this file is type "compute" > group "standard": https://github.com/oxedions/banquise/blob/alpha3/pillar/cluster/nodes/computes.sls

Then, sys admin can define for each group of each type which states (Ansible roles ?) to be installed: https://github.com/oxedions/banquise/blob/alpha3/pillar/cluster/nodes/computes_states.sls

Same for managements serveurs, and sys admin can also define some other parameters (network, nfs, etc : https://github.com/oxedions/banquise/tree/alpha3/pillar/cluster).

Then, sys admin can deploy management server and maintain it using Salt commands. All services (dhcp, dns, etc) will be installed on management nodes, and configuration files generated on the fly. Same for client side on nodes.
For example, the dhcpd.conf file contains:

{% for type in salt['pillar.get']('core:types') %}
#############################################
########## {{type}}
###
{% for group, argu in salt['pillar.get'](type, {}).items() %}
##########
# {{group}}
{%- for host, argo in argu.items() %}
{%- for network, args in argo.network.items() %}
{%- if network == "net0" %}
host {{ host }} {
hardware ethernet {{ args.hwaddr }};
fixed-address {{ args.ip }};
}
{%- endif %}
{%- endfor %}
{%- if argo.bmc is defined %}
host {{ argo.bmc.name }} {
hardware ethernet {{ argo.bmc.hwaddr }};
fixed-address {{ argo.bmc.ip }};
}
{%- endif %}
{%- endfor %}
{% endfor %}
{% endfor %}

It iterates on types, then on groups, then add each node and if present add also BMC of nodes.

In Salt, data are stored in YAML files called Pillar (https://github.com/oxedions/banquise/tree/alpha3/pillar). Logic (what to do) is in YAML files called States (https://github.com/oxedions/banquise/tree/alpha3/salt).

My questions are the following:

1. Can I use Jinja rendering directly into Ansible data files (inventories ?) ? This allows me in Banquise to generate new data deduced from the ones provided by the sys admin, and also automate some tasks, and gather data from multiple Pillars to create ready to use data. Also, it allows me to choose my structure instead of being stuck to the Salt structure.

2. Can I use structured files like YAML for inventories in Ansible ? Because each host has a lot of parameters, this allows me to structure all of these data. For what I found in Ansible documentation, inventories put all data on the same line.

3. Can I create a hierarchy like types > groups > nodes in Inventories ?

I have other questions, but these are the first ones I would like to ask :-)

My apologies for this very large question, it is just impossible do cover what can be done by a tool like Ansible in just a few hours...

With my best regards

Ox

Brian Coca

unread,
May 31, 2017, 6:59:23 PM5/31/17
to Ansible Project
Hi Ox,

Hope this answers some of your questions:

1. not by default, but you can a) generate these files from template or b) create inventory plugin that does so

2. yes, YAML has been a supported inventory format for a while now, look in examples/hosts.yml

3. no concept of types in Ansible and all hierarchies are just for 'variable resolution' Ansible itself only deals with hosts (groups become a property of each host).

----------
Brian Coca

oxed...@gmail.com

unread,
Jun 3, 2017, 2:57:36 AM6/3/17
to Ansible Project
Hi Brian Coca,

Thanks a lot for this answer.

After one week of use, I am getting used to Ansible. It is very different than Salt. Salt is more Cauliflower (hierarchy) when Ansible is more Potatoes (groups) :-)

1. Ok, I see that is is only static. I found that the Ansible capacity to "gather" groups from different files and format (JSON and YAML) even in different directories in the inventory is a good workaround. Only issue is, if I want to change a hostname, I need to change it in multiple files. This may not append a lot, but I like to have a data only once.
The idea of using a template is interesting. Do you mean playing a specific role on the ansible "server" itself ?

2. Thanks a lot! This is a very cool feature. This allows some more readable files when hosts have sophisticated vars.

3. Workaround I found is using child groups. However, I fail to get a specific information:
Lets say I create a group "bluehosts".
Then, I create two groups, "sky" and "cloud", with hosts inside, and I set them children of "bluehosts".
Is there a way to ask Ansible in templates: give me the children groups of "bluehosts" as a list so I can iterate on it ? Someting like children_groups["bluehosts"]...
Today, I need to specify manually a variable topology this way:
---
topology:
  bluehosts:
    sky:
    cloud:
So I can use it for my jinja loops.
I don't know it this value can be found by Ansible, it Ansible only add hosts in children groups inside father group, then it may not have that knowledge later.
Do you know if it's possible ?


With my best regards

Ox

Reply all
Reply to author
Forward
0 new messages