diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index 9cb0108ed6..1405d8736d 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -362,7 +362,7 @@ class VariableManager: variables['playbook_dir'] = loader.get_basedir() if host: - variables['group_names'] = [group.name for group in host.get_groups() if group.name != 'all'] + variables['group_names'] = sorted([group.name for group in host.get_groups() if group.name != 'all']) if self._inventory is not None: variables['groups'] = dict()