# Assign an existing Security Policy through Python SDK

**URL:** <https://community.f5.com/t/assign-an-existing-security-policy-through-python-sdk/42672>\
**Category:** Technical Forums\
**Tags:** super-netops, automation, asm-advanced-waf, icontrolrest, f5-python-sdk, security-policy, devops, virtual-server\
**Created:** [May 28, 2018, 6:57pm UTC](https://community.f5.com/t/assign-an-existing-security-policy-through-python-sdk/42672 "2018-05-28T18:57:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dani\_martinez\_2](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@dani\_martinez\_2](https://community.f5.com/u/dani_martinez_2)\
**Post date:** [May 28, 2018, 6:57pm UTC](https://community.f5.com/t/assign-an-existing-security-policy-through-python-sdk/42672/1 "2018-05-28T18:57:28Z")

</div>

Can I assign to an Existing Virtual Server an existing Security Policy? Not a local Traffic Policy, I have already created a Automatic Security Policy through the Deployment Wizard but I would like to automate the process through a Python Script. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Dennis\_18897](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@Dennis\_18897](https://community.f5.com/u/Dennis_18897)\
**Post date:** [July 26, 2018, 1:46pm UTC](https://community.f5.com/t/assign-an-existing-security-policy-through-python-sdk/42672/2 "2018-07-26T13:46:35Z")

</div>

Hi Dani,

Just spent some time digging into this … was quite painful. Here is a very basic and rudimentary code snippet on how to modify the virtual server assignment for a given security policy. Aka you can add or remove servers as you see fit:

```tcl
from f5.bigip import ManagementRoot
mgmt = ManagementRoot('ip', 'user', 'pass')
policies = mgmt.tm.asm.policies_s.get_collection()
policy = [p for p in policies if p.fullPath == '/partition/name'][0]
policy.modify(**{'virtualServers': []})

```

If you want to modify other parameters of the security policy you have to use tasks to apply them.

HTH, Dennis
