-
Notifications
You must be signed in to change notification settings - Fork 336
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
Correct use of security_group with azure_rm_networkinterface unclear from documentation #583
Comments
@LHurst-JM I have executed the following YAML locally and have not encountered the problem you mentioned? Can you try it again? Thank you very much!
|
I'm still getting the same my end with my yaml:
I am trying to introduce Ansible to an existing infrastructure - so in my case the NIC, NSG and VNET already exist in Azure before I ran Ansible for the first time. At the moment it looks like TerraForm might be better for doing this... |
I have also encountered this in my environment. It looks like there's a problem with the process that ultimately ends in calling the msrest Serializer class. If the security group has ever been set up to record Flow Logs, then the 'flow_logs' property will exist in the object returned by network_client.network_security_groups.list("rg-name"), but will be None regardless of the state in Azure. So when that object is sent to the azure_rm_common 'serialize_obj' method, and ultimately to the msrest serializer, it fails because it's expected to not be None. I have tried using the most recent azure-mgmt-network package and Network API version, but I get the same result from NetworkManagementClient network_security_groups.list(rg-name) regardless. I have not had the time to troubleshoot beyond that. At some point in the future if I get time I'll try sending the updated versions' through an updated msrest serializer to see if they at least accounted for the problem to get it to work. That would be a bad workaround though because then the Ansible module would have no accounting for Flow Logs, which I think we would want. I think ultimately this is a bug with the Azure python SDK, and don't see anything wrong with the azcollection code, just how the SDK handles it in this case. |
@LHurst-JM @paultaiton Can you share your test script? I will retry it! Thank you very much! |
Howdy @Fred-sun In my environment we have an Azure policy that automatically configures flow logs for any NSG, so we cant use securitygroup_info at all. |
My test script is what I included in the original report (just changed the names - everything else is as in my test case) - I am trying to bring an existing infrastructure that was manually created under Ansible's control and I fell at the first hurdle, which was my VM's NIC. I cannot confirm if there are flow logs for the NSG, I do not have visibility of that in our coporate infrastructure but I imagine that security do have them setup (also probably via policy enforcement like @paultaiton). We seem to be ignoring my first 2 points too, that it is unclear from the docs that not setting 'create_with_security_group' to True will actually remove NSGs from NICs, even if security_group is set to the existing security groups - reading the docs I expected it to not touch the existing NSG configuration in this case. The parameter name (create_with_security_group ) and the associated documentation suggests that it only does anything on creating a new NIC and then only creates a new security group - nothing in the docs suggests not setting that to True will delete the existing NIC NSG configuration or that it controls whether security_group is applied if the NIC already exists, which seems to be the case. |
@LHurst-JM Could you please provide a complete Playbook and its implementation process? This goes a long way towards solving the problem! Thank you very much! |
@LHurst-JM Upgrading azure mgmt-network to the new SDK will fix this, fixex by #729! Thank you very much! |
SUMMARY
I think there are a couple of issues with the documentation for using security_group with a NIC.
The first is that if
create_with_security_group
is set toFalse
, the security group is cleared - that is existing security groups are removed from the interface. This is not clear from the documentation, which says "Whether a security group should be be created with the NIC. If this flag set to True and no security_group set, a default security group will be created.". I think a sentence should be added that reads "If this flag is set toFalse
any existing security group will be removed from the NIC."If
create_with_security_group
is set toFalse
, any existing security group set usingsecurity_group
will not be set (the NIC's existingsecurity_group
will in fact be cleared). Again, this is unclear from the documentation which just describescreate_with_security_group
as controlling the creation of a new security group ("Whether a security group should be be created with the NIC." (amphasis mine)). The above wording change (1.) would also clarify this behaviour (i.e.security_group
only does anything withcreate_with_security_group
).If
create_with_security_group
is True and an existing security group is specifed forsecurity_group
(as documented - "An existing security group with which to associate the network interface.") the module fails for me withError creating or updating network interface nicName - Parameter 'FlowLog.target_resource_id' can not be None.
. This exception is thrown increate_or_update_nic(self, nic)
and, with _debug set toTrue
, I can see in syslog it does find the existing NSG so I am little lost as to the cause of this fault.ISSUE TYPE
COMPONENT NAME
azure_rm_networkinterface
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
CentOS 7.8.2003
STEPS TO REPRODUCE
test_playbook.yml
:inventory (as
inventory.azure_rm.yml
):EXPECTED RESULTS
Play succeeds.
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: