jesperberth.az_securitygroup

Az_securitygroup

=========

This role creates a Resource Group in Microsoft Azure.

Requirements


You need to have the Azure SDK installed. You can do this by running:

pip install 'ansible[azure]'

Role Variables


This role uses the following variables:

  • resourcegroup: Name of the resource group to create.
  • location: Azure location where the resource group will be created.
  • tag_owner: Tag owner with a specified value.
  • tag_project: Tag project with a specified value.
  • networksecuritygroup_name: Name of the Security Group.
  • rulename: Name of the rule.
  • ruleprotocol: Protocol type (Any/Tcp/Udp/Icmp).
  • rulesourceaddress: Source IP address (for example, 0.0.0.0/0).
  • ruledestinationportrange: Target port (e.g., 443 for HTTPS).
  • ruleaccess: Whether to Allow or Deny.
  • rulepriority: Priority compared to other rules.
  • ruledirection: Direction of traffic (Inbound/Outbound).

Dependencies


None

Example Playbook


Here is a simple example to create an Azure Security Group:

- hosts: localhost
  name: Create Azure Security Group
  vars:
    resourcegroup_name: resourcegroupname
    location: northeurope
    tag_owner: jesper
    tag_project: demoproject
  tasks:
    - name: Azure Security Group
      include_role:
        name: jesperberth.az_securitygroup
      vars:
        resourcegroup: "{{ resourcegroup_name }}"
        networksecuritygroup_name: SG_Network
        rulename: "AllowHTTPS"
        ruleprotocol: "Tcp"
        rulesourceaddress: 0.0.0.0/0
        ruledestinationportrange: "443"
        ruleaccess: "Allow"
        rulepriority: "101"
        ruledirection: "Inbound"

With Multiple Rules in a Loop

You can also create multiple rules in a loop like this:

- hosts: localhost
  name: Create Azure Security Group
  vars:
    resourcegroup_name: resourcegroupname
    location: northeurope
    tag_owner: jesper
    tag_project: demoproject
  tasks:
    - name: Azure Security Group
      include_role:
        name: jesperberth.az_securitygroup
      vars:
        resourcegroup: "{{ resourcegroup_name }}"
        networksecuritygroup_name: "{{ item.networksecuritygroup_name }}"
        rulename: "{{ item.rulename }}"
        ruleprotocol: "{{ item.ruleprotocol }}"
        rulesourceaddress: "{{ item.rulesourceaddress }}"
        ruledestinationportrange: "{{ item.ruledestinationportrange }}"
        ruleaccess: "{{ item.ruleaccess }}"
        rulepriority: "{{ item.rulepriority }}"
        ruledirection: "{{ item.ruledirection }}"
      loop:
        - { networksecuritygroup_name: 'SG_Network', rulename: 'AllowHTTP', ruleprotocol: 'Tcp', rulesourceaddress: '0.0.0.0/0', ruledestinationportrange: '80', ruleaccess: 'Allow', rulepriority: '102', ruledirection: 'Inbound' }
        - { networksecuritygroup_name: 'SG_Network', rulename: 'AllowHTTPS', ruleprotocol: 'Tcp', rulesourceaddress: '0.0.0.0/0', ruledestinationportrange: '443', ruleaccess: 'Allow', rulepriority: '103', ruledirection: 'Inbound' }

License


BSD

Author Information


Jesper Berth

Informazioni sul progetto

Create Network Security Group In Azure

Installa
ansible-galaxy install jesperberth.az_securitygroup
Licenza
Unknown
Download
183
Proprietario