Skip to content

Commit 8726900

Browse files
committed
Implements #1473
1 parent 3ffc54f commit 8726900

File tree

7 files changed

+25
-22
lines changed

7 files changed

+25
-22
lines changed

IM/ConfManager.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ def generate_playbooks_and_hosts(self):
10541054
contextualizes = self.inf.radl.contextualize.get_contextualize_items_by_step({1: ctxts})
10551055

10561056
# create the files for the configure sections that appears in the contextualization steps
1057-
# and add the ansible information and modules
1057+
# and add the ansible information and roles
10581058
for ctxt_num in contextualizes.keys():
10591059
for ctxt_elem in contextualizes[ctxt_num]:
10601060
if ctxt_elem.system in vm_group and ctxt_elem.get_ctxt_tool() == "Ansible":
@@ -1503,7 +1503,7 @@ def create_general_conf_file(self, conf_file, vm_list):
15031503
Create the configuration file needed by the contextualization agent
15041504
"""
15051505
# Add all the roles and collections specified in the RADL
1506-
modules = []
1506+
roles = []
15071507
collections = []
15081508
for s in self.inf.radl.systems:
15091509
for req_app in s.getApplications():
@@ -1513,32 +1513,32 @@ def create_general_conf_file(self, conf_file, vm_list):
15131513
app_name = req_app.getValue("name")[16:]
15141514
if req_app.getValue("version"):
15151515
app_name += ",%s" % req_app.getValue("version")
1516-
modules.append(app_name)
1516+
roles.append(app_name)
15171517
elif req_app.getValue("name").startswith("ansible.roles."):
15181518
# Get the roles specified by the user in the RADL
15191519
app_name = req_app.getValue("name")[14:]
15201520
if req_app.getValue("version"):
15211521
app_name += ",%s" % req_app.getValue("version")
1522-
modules.append(app_name)
1522+
roles.append(app_name)
15231523
elif req_app.getValue("name").startswith("ansible.collections."):
1524-
# Get the modules specified by the user in the RADL
1524+
# Get the collections specified by the user in the RADL
15251525
app_name = req_app.getValue("name")[20:]
15261526
if req_app.getValue("version"):
15271527
app_name += ",%s" % req_app.getValue("version")
15281528
collections.append(app_name)
15291529
else:
15301530
# Get the info about the apps from the recipes DB
1531-
vm_modules, _ = Recipe.getInfoApps([req_app])
1532-
modules.extend(vm_modules)
1531+
vm_roles, _ = Recipe.getInfoApps([req_app])
1532+
roles.extend(vm_roles)
15331533

15341534
# avoid duplicates
1535-
modules = list(set(modules))
1535+
roles = list(set(roles))
15361536
collections = list(set(collections))
15371537

15381538
conf_data = {}
15391539

15401540
conf_data['ansible_collections'] = collections
1541-
conf_data['ansible_modules'] = modules
1541+
conf_data['ansible_roles'] = roles
15421542
conf_data['playbook_retries'] = Config.PLAYBOOK_RETRIES
15431543
conf_data['vms'] = []
15441544
for vm in vm_list:

IM/CtxtAgentBase.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ def add_nat_gateway_tasks(playbook):
410410

411411
return new_playbook
412412

413-
def install_ansible_modules(self, general_conf_data, playbook):
413+
def install_ansible_roles(self, general_conf_data, playbook):
414414
new_playbook = playbook
415-
if (('ansible_modules' in general_conf_data and general_conf_data['ansible_modules']) or
415+
if (('ansible_roles' in general_conf_data and general_conf_data['ansible_roles']) or
416416
('ansible_collections' in general_conf_data and general_conf_data['ansible_collections'])):
417417
play_dir = os.path.dirname(playbook)
418418
play_filename = os.path.basename(playbook)
@@ -461,8 +461,8 @@ def install_ansible_modules(self, general_conf_data, playbook):
461461
# and then add roles
462462
galaxy_dependencies = []
463463
needs_git = False
464-
if 'ansible_modules' in general_conf_data and general_conf_data['ansible_modules']:
465-
for galaxy_name in general_conf_data['ansible_modules']:
464+
if 'ansible_roles' in general_conf_data and general_conf_data['ansible_roles']:
465+
for galaxy_name in general_conf_data['ansible_roles']:
466466
if galaxy_name:
467467
self.logger.debug("Install %s with ansible-galaxy.", galaxy_name)
468468

IM/VirtualMachine.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def getAppsToInstall(self):
391391

392392
to_install = []
393393
for req_app in requested:
394-
# discard the ansible modules
394+
# discard the ansible roles or collections
395395
if not req_app.getValue("name").startswith("ansible."):
396396
is_installed = False
397397
for inst_app in installed:

contextualization/ctxt_agent.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ def contextualize_vm(self, general_conf_data, vm_conf_data):
157157

158158
if ctxt_vm['os'] != "windows":
159159
if ctxt_vm['master']:
160-
# Install ansible modules
161-
playbook = self.install_ansible_modules(general_conf_data, playbook)
160+
# Install ansible roles
161+
playbook = self.install_ansible_roles(general_conf_data, playbook)
162162
if 'nat_instance' in ctxt_vm and ctxt_vm['nat_instance']:
163163
playbook = self.add_nat_gateway_tasks(playbook)
164164
# this step is not needed in windows systems

contextualization/ctxt_agent_dist.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ def contextualize_vm(self, general_conf_data, vm_conf_data, ctxt_vm, local):
447447
# this step is not needed in windows systems
448448
self.set_ansible_connection_local(general_conf_data, ctxt_vm)
449449
if ctxt_vm['master']:
450-
# Install ansible modules
451-
playbook = self.install_ansible_modules(general_conf_data, playbook)
450+
# Install ansible roles
451+
playbook = self.install_ansible_roles(general_conf_data, playbook)
452452
if 'nat_instance' in ctxt_vm and ctxt_vm['nat_instance']:
453453
playbook = self.add_nat_gateway_tasks(playbook)
454454
ansible_thread = self.LaunchAnsiblePlaybook(self.logger,

test/files/test.radl

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ disk.0.image.url = 'one://ramses.i3m.upv.es/1651' and
1313
disk.0.os.credentials.new.password = 'Tututu+01' and
1414
disk.0.applications contains (name = 'ansible.collections.community.general,6.3.0') and
1515
disk.0.applications contains (name = 'ansible.roles.geerlingguy.ntp') and
16+
# Test also the old version
17+
disk.0.applications contains (name = 'ansible.modules.geerlingguy.mysql') and
1618
disk.1.size=1GB and
1719
disk.1.device='hdb' and
1820
disk.1.fstype='ext4' and
@@ -51,6 +53,7 @@ configure ntp (
5153
- roles:
5254
- role: 'geerlingguy.ntp'
5355
ntp_servers: ['ntp.upv.es', 'ntp.uv.es']
56+
- role: 'geerlingguy.mysql'
5457
@end
5558
)
5659

test/unit/test_ctxt_agent.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,17 @@ def test_90_replace_vm_ip(self):
255255
data = f.read()
256256
self.assertIn(" ansible_host=%s ansible_ssh_host=%s \n" % (vm_data['ctxt_ip'], vm_data['ctxt_ip']), data)
257257

258-
def test_95_install_ansible_modules(self):
258+
def test_95_install_ansible_roles(self):
259259
ctxt_agent = CtxtAgent("")
260260
ctxt_agent.logger = self.logger
261261
general_conf_data = self.gen_general_conf()
262-
general_conf_data['ansible_modules'] = ["ansible_role",
262+
general_conf_data['ansible_roles'] = ["ansible_role",
263263
"git+https://github.com/micafer/ansible-role-hadoop|hadoop"]
264264

265265
with open("/tmp/playbook.yaml", 'w') as f:
266266
f.write("- tasks: []")
267267

268-
res = ctxt_agent.install_ansible_modules(general_conf_data, "/tmp/playbook.yaml")
268+
res = ctxt_agent.install_ansible_roles(general_conf_data, "/tmp/playbook.yaml")
269269
self.assertEqual(res, "/tmp/mod_playbook.yaml")
270270

271271
with open("/tmp/mod_playbook.yaml", 'r') as f:
@@ -290,7 +290,7 @@ def test_99_install_ansible_collections(self):
290290
with open("/tmp/playbook.yaml", 'w') as f:
291291
f.write("- tasks: []")
292292

293-
res = ctxt_agent.install_ansible_modules(general_conf_data, "/tmp/playbook.yaml")
293+
res = ctxt_agent.install_ansible_roles(general_conf_data, "/tmp/playbook.yaml")
294294
self.assertEqual(res, "/tmp/mod_playbook.yaml")
295295

296296
with open("/tmp/mod_playbook.yaml", 'r') as f:

0 commit comments

Comments
 (0)