简体   繁体   English

从 NSG 中删除子网

[英]Remove a subnet from a NSG

I have a problem when I try to remove a subnet from a NSG, for an automatic process to destroy some components inside the resource group.当我尝试从 NSG 中删除子网时遇到问题,以便自动进程销毁资源组内的某些组件。

When I try to run this command, I don't have issues to remove the NSG association with one subnet.当我尝试运行此命令时,在删除 NSG 与一个子网的关联方面没有问题。

- name: Dissociate NSG from subnet
  environment:
    AZURE_CONFIG_DIR: ./.azure
  shell: az network vnet subnet update -g Networks -n '{{ subnetName }}' --vnet-name '{{ vnetName }}' --network-security-group "" --subscription '{{ subscription }}'
  ignore_errors: yes

The problem is when I have 2 or more subnets (for different components) associate in a NSG.问题是当我在 NSG 中有 2 个或更多子网(用于不同的组件)关联时。

And If I run the command in the bash on Azure, I get this error:如果我在 Azure 上的 bash 中运行该命令,则会收到此错误:

az network vnet subnet update: error: argument --network-security-group: expected one argument
   usage: az network vnet subnet update [-h] [--verbose] [--debug]
                 [--output {json,jsonc,table,tsv,yaml,none}]

I am trying to see how I can disassociate all the subnets it contains in the NSG, without having to make several blocks for each subnets.我正在尝试了解如何取消 NSG 中包含的所有子网的关联,而不必为每个子网创建多个块。

you could do something like this:你可以做这样的事情:

az network nsg show -n nsg_name -g rg_name --query 'subnets[].id' -o tsv

to find out all the subnets that the NSG is attached to and then you can use those to remove NSG's from those subnets.找出 NSG 附加到的所有子网,然后您可以使用这些子网从这些子网中删除 NSG。

az network vnet subnet update --ids [] (resource IDs space-delimited) --network-security-group ""

or you could iterate them one by one:或者你可以一一迭代它们:

az network nsg show -n nsg_name -g rg_name --query 'subnets[].id' -o tsv |
  xargs -L 1 az network vnet subnet update --network-security-group "" --ids 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM