New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vm scale sets to azure dynamic inventory #40327

Open
wants to merge 13 commits into
base: devel
from

Conversation

@paktek123

paktek123 commented May 17, 2018

SUMMARY

Adds support for running playbooks on VM Scale Sets VMs. Filter the scale sets with tags, resource groups and location.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

contrib

ANSIBLE VERSION
2.5.2
@ansibot

This comment has been minimized.

@ansibot

This comment has been minimized.

Contributor

ansibot commented May 17, 2018

The test ansible-test sanity --test pylint [explain] failed with 2 errors:

contrib/inventory/azure_rm.py:620:0: trailing-whitespace Trailing whitespace
contrib/inventory/azure_rm.py:636:0: trailing-whitespace Trailing whitespace

The test ansible-test sanity --test pep8 [explain] failed with 4 errors:

contrib/inventory/azure_rm.py:620:93: W291 trailing whitespace
contrib/inventory/azure_rm.py:636:24: W291 trailing whitespace
contrib/inventory/azure_rm.py:651:76: E203 whitespace before ':'
contrib/inventory/azure_rm.py:658:118: E202 whitespace before ']'

click here for bot help

@yuwzho

This comment has been minimized.

Contributor

yuwzho commented May 22, 2018

contrib/inventory/azure_rm.py Outdated
host_vars['fqdn'] = public_ip_address.dns_settings.fqdn
# here we are assuming all vmss vms have private ip addresses
if vmss_vm:
host_vars['ansible_host'] = machine.private_ip_address

This comment has been minimized.

@yungezz

yungezz May 23, 2018

Contributor

will need port also to access those vm

This comment has been minimized.

@paktek123

paktek123 May 31, 2018

Hi @yungezz , thanks for reviewing. Sorry I don't understand. Can you please elaborate? I assumed the port was passed when running the ansible-playbook command.

This comment has been minimized.

@yungezz

yungezz Jun 13, 2018

Contributor

when vmss has loadbalancer, and user want to access vmss instance with public ip, will need port in inbound nat rules.

This comment has been minimized.

@paktek123

paktek123 Jun 14, 2018

thanks, I understand now

host_vars['private_ip_alloc_method'] = ip_config.private_ip_allocation_method
if self.use_private_ip:
host_vars['ansible_host'] = ip_config.private_ip_address
if ip_config.public_ip_address:

This comment has been minimized.

@yungezz

yungezz May 23, 2018

Contributor

get publicip info for vmss if has load balancer

This comment has been minimized.

@paktek123

paktek123 May 31, 2018

added public ip info for vmss from the ip configuration in next commit

if network_interface.primary:
if self.group_by_security_group and \
self._security_groups[resource_group].get(network_interface.id, None):
host_vars['security_group'] = \

This comment has been minimized.

@yungezz

yungezz May 23, 2018

Contributor

get security group info from vnet

This comment has been minimized.

@paktek123

paktek123 May 31, 2018

I cannot seem to find a way to associate the network_interface with the subnet . For example here is an id:
/subscriptions/redacted/resourceGroups/test/providers/Microsoft.Compute/virtualMachineScaleSets/testvmss/virtualMachines/0/networkInterfaces/testvmss-nic'

The virtual machine profile inside the vmss, returns None for network security groups :(
Also the nic doesn't seem to be part of the resource group.

Only solution I think is running:

self._network_client.network_interfaces.list_virtual_machine_scale_set_network_interfaces(resource_group, name)

I get the subnet id and from that get the name and list the security groups underneath. I'll work on that on my next commit.

This comment has been minimized.

@yungezz

yungezz Jun 8, 2018

Contributor

you can get subnet info from self.compute_client.virtual_machine_scale_sets.get(self.resource_group, self.name)

@yungezz

This comment has been minimized.

Contributor

yungezz commented May 25, 2018

hello @paktek123 , thanks for contribution, could you pls look at comments?

@paktek123

This comment has been minimized.

paktek123 commented May 30, 2018

yup looking, sorry for the delay

@ansibot ansibot added stale_ci and removed stale_ci labels May 30, 2018

@ansibot ansibot added the stale_ci label Jun 13, 2018

@yungezz

This comment has been minimized.

Contributor

yungezz commented Jun 19, 2018

@paktek123 HI Neeran, the changes looks good and inventory by vmss is very useful. Could you pls update based on comments? pls let me know if any help need, I can fork your branch to help if permission granted.

@yungezz

This comment has been minimized.

Contributor

yungezz commented Jun 28, 2018

@paktek123 would you like to grant me forked repo permission to continue the pr? thanks.

@paktek123

This comment has been minimized.

paktek123 commented Jul 11, 2018

Hi @yungezz

Sorry havent had time to work on this lately. I have given you write access to the forked ansible repo. Please let me know if you need help thanks.

@yungezz yungezz force-pushed the paktek123:add-vm-scale-sets-to-azure-dynamic-inventory branch to 13efcac Aug 15, 2018

@yungezz

This comment has been minimized.

Contributor

yungezz commented Aug 15, 2018

ready_for_review

@Fred-sun

This comment has been minimized.

Contributor

Fred-sun commented Aug 15, 2018

@joshuaclausen @yuwzho @zikalino could you help review this PR? Thanks!

@Fred-sun

This comment has been minimized.

Contributor

Fred-sun commented Aug 20, 2018

@joshuaclausen @yuwzho @zikalino could you help review this PR again? Thanks!

1 similar comment
@Fred-sun

This comment has been minimized.

Contributor

Fred-sun commented Aug 24, 2018

@joshuaclausen @yuwzho @zikalino could you help review this PR again? Thanks!

@ansibot ansibot added the stale_ci label Aug 24, 2018

@joshuaclausen

This comment has been minimized.

joshuaclausen commented Aug 25, 2018

If a vmss machine doesn't have a public IP address I get the following error:
TypeError: <azure.mgmt.network.v2017_06_01.models.public_ip_address.PublicIPAddress object at 0x7f2aa1dad0d0> is not JSON serializable

@yungezz

This comment has been minimized.

Contributor

yungezz commented Aug 27, 2018

@joshuaclausen thanks for reporting the issue. I didn't meet the error when working with vmss with private ip only. Will check it and update here.

@joshuaclausen

This comment has been minimized.

joshuaclausen commented Aug 27, 2018

I got around the error by appending ".ip_address" to the end of the following line:
vm.public_ip_address = nic_config.get("public_ip_address", None).ip_address

However, the final host_vars['public_ip'] never had the public IP assigned, so it was "null". After some more digging, it seems no public IPs come back in the function "_get_vmss_vm_instances". When I print out the contents of nic_config.get("public_ip_address") as used within that function, I get "None" values for the public IP. The following is what I get for all the nics in that function:

{'zones': None, 'dns_settings': None, 'name': None, 'tags': None, 'public_ip_address_version': None, 'public_ip_allocation_method': None, 'resource_guid': None, 'provisioning_state': None, 'ip_address': None, 'etag': None, 'location': None, 'ip_configuration': None, 'idle_timeout_in_minutes': None, 'type': None, 'id': u'/subscriptions/..../resourceGroups/.../providers/Microsoft.Compute/virtualMachineScaleSets/.../virtualMachines/11/networkInterfaces/primary-nic-cfg/ipConfigurations/primary-nic-ip-cfg/publicIPAddresses/...'}

I can confirm the machines in the vmss do indeed have a public IP, and I can connect to them on it. I'll keep poking, but it's almost as though we're not getting any nic config data that includes the public IP. I'm rather new to Ansible and Python, so forgive any noob mistakes ;)

@Fred-sun

This comment has been minimized.

Contributor

Fred-sun commented Sep 18, 2018

@yungezz do you have any updated about this PR? Thanks!

@moh-abk

This comment has been minimized.

moh-abk commented Sep 21, 2018

Any updates on this?

@yungezz

This comment has been minimized.

Contributor

yungezz commented Sep 22, 2018

@moh-abk I was on something else recently. I will work on next week. For your information, there's a new inventory with batch api https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/inventory/azure_rm.py, you may want to have a try if urgent need.

@Fred-sun

This comment has been minimized.

Contributor

Fred-sun commented Oct 10, 2018

1 similar comment
@Fred-sun

This comment has been minimized.

Contributor

Fred-sun commented Oct 24, 2018

@Fred-sun

This comment has been minimized.

Contributor

Fred-sun commented Nov 13, 2018

@ansible ansible deleted a comment from Fred-sun Nov 22, 2018

@Fred-sun

This comment has been minimized.

Contributor

Fred-sun commented Nov 22, 2018

@paktek123 Thanks for contribution. This inventory script is in maintenance mode: only critical bug fixes but no new features. There's new Azure external inventory script at here with better performance and latest new features. Pls move your contribution there. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment