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:
commit
6fb09d73b1
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user