Skip to content

Commit

Permalink
add group_by_os_family in azure dynamic inventory (ansible#40702)
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneDeneuve authored and yungezz committed Aug 9, 2018
1 parent adc0efe commit 379fb87
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions contrib/inventory/azure_rm.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ include_powerstate=yes
group_by_resource_group=yes
group_by_location=yes
group_by_security_group=yes
group_by_os_family=yes
group_by_tag=yes
10 changes: 9 additions & 1 deletion contrib/inventory/azure_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
group_by_location='AZURE_GROUP_BY_LOCATION',
group_by_security_group='AZURE_GROUP_BY_SECURITY_GROUP',
group_by_tag='AZURE_GROUP_BY_TAG',
group_by_os_family='AZURE_GROUP_BY_OS_FAMILY',
use_private_ip='AZURE_USE_PRIVATE_IP'
)

Expand Down Expand Up @@ -572,6 +573,7 @@ def __init__(self):
self.replace_dash_in_groups = False
self.group_by_resource_group = True
self.group_by_location = True
self.group_by_os_family = True
self.group_by_security_group = True
self.group_by_tag = True
self.include_powerstate = True
Expand Down Expand Up @@ -706,7 +708,7 @@ def _load_machines(self, machines):

host_vars['os_disk'] = dict(
name=machine.storage_profile.os_disk.name,
operating_system_type=machine.storage_profile.os_disk.os_type.value
operating_system_type=machine.storage_profile.os_disk.os_type.value.lower()
)

if self.include_powerstate:
Expand Down Expand Up @@ -811,10 +813,16 @@ def _add_host(self, vars):

host_name = self._to_safe(vars['name'])
resource_group = self._to_safe(vars['resource_group'])
operating_system_type = self._to_safe(vars['os_disk']['operating_system_type'].lower())
security_group = None
if vars.get('security_group'):
security_group = self._to_safe(vars['security_group'])

if self.group_by_os_family:
if not self._inventory.get(operating_system_type):
self._inventory[operating_system_type] = []
self._inventory[operating_system_type].append(host_name)

if self.group_by_resource_group:
if not self._inventory.get(resource_group):
self._inventory[resource_group] = []
Expand Down
10 changes: 9 additions & 1 deletion docs/docsite/rst/scenario_guides/guide_azure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ By default hosts are grouped by:
* security group name
* tag key
* tag key_value
* os_disk operating_system_type (Windows/Linux)

You can control host groupings and host selection by either defining environment variables or creating an
azure_rm.ini file in your current working directory.
Expand All @@ -344,6 +345,7 @@ Control grouping using the following variables defined in the environment:
* AZURE_GROUP_BY_LOCATION=yes
* AZURE_GROUP_BY_SECURITY_GROUP=yes
* AZURE_GROUP_BY_TAG=yes
* AZURE_GROUP_BY_OS_FAMILY=yes

Select hosts within specific resource groups by assigning a comma separated list to:

Expand Down Expand Up @@ -390,7 +392,7 @@ file will contain the following:
group_by_location=yes
group_by_security_group=yes
group_by_tag=yes
group_by_os_family=yes
Examples
........
Expand All @@ -402,6 +404,12 @@ Here are some examples using the inventory script:
# Execute /bin/uname on all instances in the Testing resource group
$ ansible -i azure_rm.py Testing -m shell -a "/bin/uname -a"
# Execute win_ping on all Windows instances
$ ansible -i azure_rm.py windows -m win_ping
# Execute win_ping on all Windows instances
$ ansible -i azure_rm.py winux -m ping
# Use the inventory script to print instance specific information
$ ./ansible/contrib/inventory/azure_rm.py --host my_instance_host_name --resource-groups=Testing --pretty
Expand Down

0 comments on commit 379fb87

Please sign in to comment.