1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

Merge pull request #3801 from ansible/fix-jinja-host-name

[3.6.0] fix jinja host name
This commit is contained in:
Ryan Petrello 2019-10-22 06:54:01 -04:00 committed by GitHub
commit 6fb09d73b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -28,6 +28,7 @@ from awx.main.models.inventory import (
Host
)
from awx.main.utils.mem_inventory import MemInventory, dict_to_mem_data
from awx.main.utils.safe_yaml import sanitize_jinja
# other AWX imports
from awx.main.models.rbac import batch_role_ancestor_rebuilding
@ -795,6 +796,10 @@ class Command(BaseCommand):
if self.instance_id_var:
instance_id = self._get_instance_id(mem_host.variables)
host_attrs['instance_id'] = instance_id
try:
sanitize_jinja(mem_host_name)
except ValueError as e:
raise ValueError(str(e) + ': {}'.format(mem_host_name))
db_host = self.inventory.hosts.update_or_create(name=mem_host_name, defaults=host_attrs)[0]
if enabled is False:
logger.debug('Host "%s" added (disabled)', mem_host_name)

View File

@ -61,6 +61,7 @@ from awx.main.models.notifications import (
)
from awx.main.models.credential.injectors import _openstack_data
from awx.main.utils import _inventory_updates, region_sorting, get_licenser
from awx.main.utils.safe_yaml import sanitize_jinja
__all__ = ['Inventory', 'Host', 'Group', 'InventorySource', 'InventoryUpdate',
@ -754,6 +755,13 @@ class Host(CommonModelNameNotUnique, RelatedJobsMixin):
update_host_smart_inventory_memberships.delay()
connection.on_commit(on_commit)
def clean_name(self):
try:
sanitize_jinja(self.name)
except ValueError as e:
raise ValidationError(str(e) + ": {}".format(self.name))
return self.name
def save(self, *args, **kwargs):
self._update_host_smart_inventory_memeberships()
super(Host, self).save(*args, **kwargs)