Skip to content

Commit 04607ff

Browse files
authored
Merge pull request #1472 from grycap/ansible_roles
Ansible roles - Implements #1473
2 parents ad683e0 + 7a4872b commit 04607ff

21 files changed

+71
-214
lines changed

IM/ConfManager.py

+11
Original file line numberDiff line numberDiff line change
@@ -1411,8 +1411,12 @@ def configure_ansible(self, ssh, tmp_dir, ansible_version=None):
14111411
for s in self.inf.radl.systems:
14121412
for req_app in s.getApplications():
14131413
if req_app.getValue("name").startswith("ansible.modules."):
1414+
# Mantain it for compatibility
14141415
# Get the modules specified by the user in the RADL
14151416
modules.append(req_app.getValue("name")[16:])
1417+
elif req_app.getValue("name").startswith("ansible.roles."):
1418+
# Get the roles specified by the user in the RADL
1419+
modules.append(req_app.getValue("name")[14:])
14161420
elif req_app.getValue("name").startswith("ansible.collections."):
14171421
# Get the modules specified by the user in the RADL
14181422
collections.append(req_app.getValue("name")[20:])
@@ -1504,11 +1508,18 @@ def create_general_conf_file(self, conf_file, vm_list):
15041508
for s in self.inf.radl.systems:
15051509
for req_app in s.getApplications():
15061510
if req_app.getValue("name").startswith("ansible.modules."):
1511+
# Mantain it for compatibility
15071512
# Get the modules specified by the user in the RADL
15081513
app_name = req_app.getValue("name")[16:]
15091514
if req_app.getValue("version"):
15101515
app_name += ",%s" % req_app.getValue("version")
15111516
modules.append(app_name)
1517+
elif req_app.getValue("name").startswith("ansible.roles."):
1518+
# Get the roles specified by the user in the RADL
1519+
app_name = req_app.getValue("name")[14:]
1520+
if req_app.getValue("version"):
1521+
app_name += ",%s" % req_app.getValue("version")
1522+
modules.append(app_name)
15121523
elif req_app.getValue("name").startswith("ansible.collections."):
15131524
# Get the modules specified by the user in the RADL
15141525
app_name = req_app.getValue("name")[20:]

IM/InfrastructureManager.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1423,16 +1423,19 @@ def get_auth_from_vault(auth):
14231423
vault_host = None
14241424
vault_path = None
14251425
vault_role = None
1426+
vault_mount_point = None
14261427
if "host" in vault_auth[0]:
14271428
vault_host = vault_auth[0]["host"]
14281429
else:
14291430
InfrastructureManager.logger.warning("Vault credentials without host.")
14301431
return auth
14311432
if "path" in vault_auth[0]:
14321433
vault_path = vault_auth[0]["path"]
1434+
if "mount_point" in vault_auth[0]:
1435+
vault_mount_point = vault_auth[0]["mount_point"]
14331436
if "role" in vault_auth[0]:
14341437
vault_role = vault_auth[0]["role"]
1435-
vault = VaultCredentials(vault_host, vault_path, vault_role, Config.VERIFI_SSL)
1438+
vault = VaultCredentials(vault_host, vault_mount_point, vault_path, vault_role, Config.VERIFI_SSL)
14361439
creds = vault.get_creds(vault_auth[0]["token"])
14371440
creds.extend(auth.auth_list)
14381441
creds.remove(vault_auth[0])

IM/tosca/Tosca.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ def _get_node_artifacts(node):
16391639
def _add_ansible_roles(self, node, nodetemplates, system):
16401640
"""
16411641
Find all the roles and collections to be applied to this node and
1642-
add them to the system as ansible.modules.* or ansible.collections.*
1642+
add them to the system as ansible.roles.* or ansible.collections.*
16431643
in 'disk.0.applications'
16441644
"""
16451645
collections = []
@@ -1654,7 +1654,7 @@ def _add_ansible_roles(self, node, nodetemplates, system):
16541654

16551655
if compute and compute.name == node.name:
16561656
# Get the artifacts to see if there is a ansible galaxy role
1657-
# and add it as an "ansible.modules" app requirement in RADL
1657+
# and add it as an "ansible.roles" app requirement in RADL
16581658
artifacts = self._get_node_artifacts(other_node)
16591659
for _, artifact in artifacts.items():
16601660
if ('type' in artifact and artifact['type'] == 'tosca.artifacts.AnsibleGalaxy.role' and
@@ -1674,7 +1674,7 @@ def _add_ansible_roles(self, node, nodetemplates, system):
16741674

16751675
for role in roles:
16761676
app_features = Features()
1677-
app_features.addFeature(Feature('name', '=', 'ansible.modules.' + role))
1677+
app_features.addFeature(Feature('name', '=', 'ansible.roles.' + role))
16781678
feature = Feature('disk.0.applications', 'contains', app_features)
16791679
system.addFeature(feature)
16801680

IM/vault.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626

2727
class VaultCredentials():
2828

29-
def __init__(self, vault_url, vault_path=None, role=None, ssl_verify=False):
30-
self.vault_path = "credentials/"
31-
if vault_path:
32-
self.vault_path = vault_path
29+
def __init__(self, vault_url, vault_mount_point=None, vault_path=None, role=None, ssl_verify=False):
30+
self.mount_point = "credentials/"
31+
if vault_mount_point:
32+
self.mount_point = vault_mount_point
33+
self.path = vault_path
3334
self.role = role
3435
self.client = None
3536
self.ssl_verify = ssl_verify
@@ -62,9 +63,12 @@ def _login(self, token):
6263
def get_creds(self, token):
6364
vault_entity_id = self._login(token)
6465
data = []
66+
path = self.path
67+
if not path:
68+
path = vault_entity_id
6569

6670
try:
67-
creds = self.client.secrets.kv.v1.read_secret(path=vault_entity_id, mount_point=self.vault_path)
71+
creds = self.client.secrets.kv.v1.read_secret(path=path, mount_point=self.mount_point)
6872
for cred_json in creds["data"].values():
6973
new_item = json.loads(cred_json)
7074
if 'enabled' not in new_item or new_item['enabled']:

doc/source/radl.rst

+11-10
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ machine. The supported features are:
410410
can be installed during the contextualization of the virtual machine if it
411411
is not installed.
412412

413-
There are some **special** type of application that starts with ``ansible.modules.`` or ``ansible.collections.``.
413+
There are some **special** type of application that starts with ``ansible.roles.``
414+
(``ansible.modules.`` in < IM 1.14 ) or ``ansible.collections.``.
414415
These applications installs `ansible roles <https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse_roles.html>`_ or
415416
`ansible collections <https://docs.ansible.com/ansible/latest/collections_guide/index.html>`_
416417
that can be used in the ``configure`` sections of the RADL.
@@ -420,14 +421,14 @@ machine. The supported features are:
420421

421422
There are three type of ansible modules/roles:
422423

423-
* `Ansible Galaxy <https://galaxy.ansible.com/>`_ roles: ``ansible.modules.micafer.hadoop``: The user
424-
specifies the name of the galaxy role afther the string ``ansible.modules.``
425-
* HTTP URL: ``ansible.modules.https://github.com/micafer/ansible-role-hadoop/archive/master.tar.gz|hadoop``: The user
426-
specifies an HTTP URL afther the string ``ansible.modules.``. The file must be compressed.
424+
* `Ansible Galaxy <https://galaxy.ansible.com/>`_ roles: ``ansible.roles.micafer.hadoop``: The user
425+
specifies the name of the galaxy role afther the string ``ansible.roles.``
426+
* HTTP URL: ``ansible.roles.https://github.com/micafer/ansible-role-hadoop/archive/master.tar.gz|hadoop``: The user
427+
specifies an HTTP URL afther the string ``ansible.roles.``. The file must be compressed.
427428
It must contain the ansible role content. Furthermore the user can specify the rolename using
428429
a ``|`` afther the url, as shown in the example.
429-
* Git Repo: ``ansible.modules.git+https://github.com/micafer/ansible-role-hadoop|hadoop``: The user specifies a Git repo
430-
(using the git scheme in the URL) afther the string ``ansible.modules.``. Furthermore the
430+
* Git Repo: ``ansible.roles.git+https://github.com/micafer/ansible-role-hadoop|hadoop``: The user specifies a Git repo
431+
(using the git scheme in the URL) afther the string ``ansible.roles.``. Furthermore the
431432
user can specify the rolename using a ``|`` afther the url, as shown in the example.
432433

433434
``nat_instance = yes|no``
@@ -592,7 +593,7 @@ Including roles or collections of Ansible Galaxy
592593
-------------------------------------------------
593594

594595
To include a role available in Ansible Galaxy a special application requirement
595-
must be added: it must start with: "ansible.modules" as shown in the following
596+
must be added: it must start with: "ansible.roles" as shown in the following
596597
example. In this case the Ansible Galaxy role called "micafer.hadoop" will be installed::
597598

598599
network net (outbound = 'yes')
@@ -603,7 +604,7 @@ example. In this case the Ansible Galaxy role called "micafer.hadoop" will be in
603604
net_interface.0.connection = "net" and
604605
disk.0.os.name = "linux" and
605606
disk.0.os.flavour = "ubuntu" and
606-
disk.0.applications contains (name="ansible.modules.micafer.hadoop")
607+
disk.0.applications contains (name="ansible.roles.micafer.hadoop")
607608
)
608609

609610
Then the configuration section of the RADL can use the role as described in the role's
@@ -620,7 +621,7 @@ documentation. In the particular case of the "micafer.hadoop" role is the follow
620621

621622
You can request an specific version/tag/branch of a galaxy role using the following format::
622623

623-
disk.0.applications contains (name="ansible.modules.micafer.hadoop,v1.0.0")
624+
disk.0.applications contains (name="ansible.roles.micafer.hadoop,v1.0.0")
624625

625626
Similarly, to include a collection available in Ansible Galaxy it must start with:
626627
"ansible.collections" as shown in the following example. In this case the Ansible Galaxy

examples/galaxy.radl

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ net_interface.0.connection = 'privada' and
99
net_interface.0.dns_name = 'slurmserver' and
1010
disk.0.os.name='linux' and
1111
disk.0.os.flavour='ubuntu' and
12-
disk.0.applications contains (name='ansible.modules.indigo-dc.slurm') and
13-
disk.0.applications contains (name='ansible.modules.indigo-dc.nfs') and
14-
disk.0.applications contains (name='ansible.modules.grycap.galaxy')
12+
disk.0.applications contains (name='ansible.roles.indigo-dc.slurm') and
13+
disk.0.applications contains (name='ansible.roles.indigo-dc.nfs') and
14+
disk.0.applications contains (name='ansible.roles.grycap.galaxy')
1515
)
1616

1717
system wn (

examples/ganglia.radl

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ net_interface.0.dns_name = 'front' and
1212
disk.0.os.name='linux' and
1313
disk.0.os.flavour='scientific' and
1414
disk.0.os.version>='6' and
15-
disk.0.applications contains (name='ansible.modules.micafer.ganglia')
15+
disk.0.applications contains (name='ansible.roles.micafer.ganglia')
1616
)
1717

1818
system wn (

examples/glusterfs.radl

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ net_interface.0.dns_name = 'glusterfe' and
1212
disk.0.os.name='linux' and
1313
disk.0.os.flavour='ubuntu' and
1414
disk.0.os.version>='18.04' and
15-
disk.0.applications contains (name='ansible.modules.geerlingguy.glusterfs')
15+
disk.0.applications contains (name='ansible.roles.geerlingguy.glusterfs')
1616
)
1717

1818
system wn (

examples/hadoop.radl

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ disk.0.os.flavour='ubuntu' and
1313
disk.0.os.version='12.04'and
1414
#disk.0.os.flavour='scientific' and
1515
#disk.0.os.version>='6' and
16-
disk.0.applications contains (name='ansible.modules.micafer.hadoop')
16+
disk.0.applications contains (name='ansible.roles.micafer.hadoop')
1717
)
1818

1919
system wn (

examples/kubernetes.radl

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ net_interface.1.dns_name = 'kubeserverpublic' and
1212
disk.0.os.name='linux' and
1313
disk.0.os.flavour='ubuntu' and
1414
disk.0.os.version>='16.04' and
15-
disk.0.applications contains (name='ansible.modules.grycap.kubernetes') and
16-
disk.0.applications contains (name='ansible.modules.grycap.nfs')
15+
disk.0.applications contains (name='ansible.roles.grycap.kubernetes') and
16+
disk.0.applications contains (name='ansible.roles.grycap.nfs')
1717
)
1818

1919
system wn (

examples/slurm.radl

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ net_interface.0.connection = 'privada' and
99
net_interface.0.dns_name = 'slurmserver' and
1010
disk.0.os.name='linux' and
1111
disk.0.os.flavour='ubuntu' and
12-
disk.0.applications contains (name='ansible.modules.indigo-dc.slurm') and
13-
disk.0.applications contains (name='ansible.modules.indigo-dc.nfs')
12+
disk.0.applications contains (name='ansible.roles.indigo-dc.slurm') and
13+
disk.0.applications contains (name='ansible.roles.indigo-dc.nfs')
1414
)
1515

1616
system wn (

examples/swarm.radl

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ net_interface.1.connection = 'privada' and
99
net_interface.0.dns_name = 'swarmmanager' and
1010
disk.0.os.name='linux' and
1111
disk.0.os.flavour='ubuntu' and
12-
disk.0.applications contains (name='ansible.modules.grycap.swarm')
12+
disk.0.applications contains (name='ansible.roles.grycap.swarm')
1313
)
1414

1515
system wn (

kube/kube_im_ha.radl

-118
This file was deleted.

0 commit comments

Comments
 (0)