Documentation

alicloud_security_group - Create, Query or Delete Security Group.

DEPRECATED

Removed in Ansible:
 version: 1.5.0
Why:Alibaba Cloud module name prefix “ali” will be more concise.
Alternative:Use ali_security_group instead.

Synopsis

  • Create and Delete Security Group, and it contains security group rules management.

Requirements

The below requirements are needed on the host that executes this module.

  • footmark >= 1.1.16
  • python >= 2.6

Parameters

Parameter Choices/Defaults Comments
alicloud_access_key
Aliyun Cloud access key. If not set then the value of environment variable ALICLOUD_ACCESS_KEY, ALICLOUD_ACCESS_KEY_ID will be used instead.

aliases: access_key_id, access_key
alicloud_region
The Aliyun Cloud region to use. If not specified then the value of environment variable ALICLOUD_REGION, ALICLOUD_REGION_ID will be used instead.

aliases: region, region_id
alicloud_secret_key
Aliyun Cloud secret key. If not set then the value of environment variable ALICLOUD_SECRET_KEY, ALICLOUD_SECRET_ACCESS_KEY will be used instead.

aliases: secret_access_key, secret_key
alicloud_security_token
The Aliyun Cloud security token. If not specified then the value of environment variable ALICLOUD_SECURITY_TOKEN will be used instead.

aliases: security_token
description
Description of the security group, which is a string of 2 to 256 characters.
It cannot begin with http:// or https://.
group_id
Security group ID. It is required when deleting or querying security group or performing rules authorization.
group_name
Name of the security group, which is a string of 2 to 128 Chinese or English characters. It must begin with an uppercase/lowercase letter or a Chinese character and can contain numerals, "_", "." or "-". It cannot begin with http:// or https://.

aliases: name
rules
List of hash/dictionaries firewall inbound rules to enforce in this group.
nic_type
    Choices:
  • internet ←
  • intranet
Network type
ip_protocol
required
    Choices:
  • tcp
  • udp
  • icmp
  • gre
  • all
IP protocol

aliases: proto
priority
    Choices:
  • 1~100
Default:
1
Authorization policy priority
port_range
required
The range of port numbers. Tcp and udp's valid range is 1 to 65535, and other protocol's valid value is -1/-1.
source_group_id
The source security group id.

aliases: group_id
source_group_owner_id
The source security group owner id.

aliases: group_owner_id
policy
    Choices:
  • accept ←
  • drop
Authorization policy
source_cidr_ip
The source IP address range

aliases: cidr_ip
rules_egress
List of hash/dictionaries firewall outbound rules to enforce in this group. Keys allowed are:ip_protocol, port_range, dest_group_id, dest_group_owner_id, dest_cidr_ip, policy, priority,nic_type. And these keys's attribution same as rules keys.
nic_type
    Choices:
  • internet ←
  • intranet
Network type
dest_cidr_ip
The destination IP address range

aliases: cidr_ip
ip_protocol
required
    Choices:
  • tcp
  • udp
  • icmp
  • gre
  • all
IP protocol

aliases: proto
priority
    Choices:
  • 1~100
Default:
1
Authorization policy priority
port_range
required
The range of port numbers. Tcp and udp's valid range is 1 to 65535, and other protocol's valid value is "-1/-1".
policy
    Choices:
  • accept ←
  • drop
Authorization policy
dest_group_id
The destination security group id.

aliases: group_id
dest_group_owner_id
The destination security group owner id.

aliases: group_owner_id
state
    Choices:
  • present ←
  • absent
Create, delete a security group
vpc_id
ID of the VPC to which the security group belongs.

Notes

Note

  • If parameters are not set within the module, the following environment variables can be used in decreasing order of precedence ALICLOUD_ACCESS_KEY or ALICLOUD_ACCESS_KEY_ID, ALICLOUD_SECRET_KEY or ALICLOUD_SECRET_ACCESS_KEY, ALICLOUD_REGION or ALICLOUD_REGION_ID, ALICLOUD_SECURITY_TOKEN
  • ALICLOUD_REGION or ALICLOUD_REGION_ID can be typically be used to specify the ALICLOUD region, when required, but this can also be configured in the footmark config file

Examples

#
# Provisioning new Security Group
#

# Basic provisioning example to create security group
- name: create security group
  hosts: localhost
  connection: local
  vars:
    alicloud_access_key: xxxxxxxxxx
    alicloud_secret_key: xxxxxxxxxx
    alicloud_region: cn-shenzhen
  tasks:
    - name: create security grp
      alicloud_security_group:
        alicloud_access_key: '{{ alicloud_access_key }}'
        alicloud_secret_key: '{{ alicloud_secret_key }}'
        alicloud_region: '{{ alicloud_region }}'
        group_name: 'AliyunSG'


# Basic provisioning example authorize security group
- name: authorize security grp
  hosts: localhost
  connection: local
  vars:
    alicloud_access_key: xxxxxxxxxx
    alicloud_secret_key: xxxxxxxxxx
    alicloud_region: cn-shenzhen
  tasks:
    - name: authorize security group
      alicloud_security_group:
        alicloud_access_key: '{{ alicloud_access_key }}'
        alicloud_secret_key: '{{ alicloud_secret_key }}'
        group_id: xxxxxxxxxx
        alicloud_region: '{{ alicloud_region }}'
        rules:
          - ip_protocol: tcp
            port_range: 1/122
            source_cidr_ip: '10.159.6.18/12'
        rules_egress:
          - proto: all
            port_range: -1/-1
            dest_group_id: xxxxxxxxxx
            nic_type: intranet


# Provisioning example create and authorize security group
- name: create and authorize security group
  hosts: localhost
  connection: local
  vars:
    alicloud_access_key: xxxxxxxxxx
    alicloud_secret_key: xxxxxxxxxx
    alicloud_region: cn-shenzhen
  tasks:
    - name: create and authorize security grp
      alicloud_security_group:
        alicloud_access_key: '{{ alicloud_access_key }}'
        alicloud_secret_key: '{{ alicloud_secret_key }}'
        group_name: 'AliyunSG'
        description: 'an example ECS group'
        alicloud_region: '{{ alicloud_region }}'
        rules:
          - ip_protocol: tcp
            port_range: 1/122
            source_cidr_ip: '10.159.6.18/12'
            priority: 10
            policy: drop
            nic_type: intranet
        rules_egress:
          - proto: all
            port_range: -1/-1
            dest_group_id: xxxxxxxxxx
            group_owner_id: xxxxxxxxxx
            priority: 10
            policy: accept
            nic_type: intranet


# Provisioning example to delete security group
- name: delete security grp
  hosts: localhost
  connection: local
  vars:
    alicloud_access_key: xxxxxxxxxx
    alicloud_secret_key: xxxxxxxxxx
    alicloud_region: us-west-1
    group_ids:
     - xxxxxxxxxx
    state: absent
  tasks:
    - name: delete security grp
      alicloud_security_group:
        alicloud_access_key: '{{ alicloud_access_key }}'
        alicloud_secret_key: '{{ alicloud_secret_key }}'
        alicloud_region: '{{ alicloud_region }}'
        group_ids: '{{ group_ids }}'
        state: '{{ state }}'

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
group
dict
when present
Details about the security group that was created

Sample:
{'region_id': 'cn-beijing', 'tags': {}, 'rules': [{'nic_type': 'internet', 'direction': 'ingress', 'dest_cidr_ip': '', 'description': '', 'create_time': '2017-06-19T02:43:29Z', 'source_cidr_ip': '192.168.0.54/32', 'ip_protocol': 'TCP', 'source_group_owner_account': '', 'dest_group_owner_account': '', 'dest_group_name': '', 'priority': 1, 'port_range': '80/86', 'source_group_id': '', 'policy': 'Accept', 'source_group_name': '', 'dest_group_id': ''}, {'nic_type': 'internet', 'direction': 'egress', 'dest_cidr_ip': '47.89.23.33/32', 'description': '', 'create_time': '2017-06-19T02:43:30Z', 'source_cidr_ip': '', 'ip_protocol': 'TCP', 'source_group_owner_account': '', 'dest_group_owner_account': '', 'dest_group_name': '', 'priority': 1, 'port_range': '8080/8085', 'source_group_id': '', 'policy': 'Accept', 'source_group_name': '', 'dest_group_id': ''}], 'vpc_id': '', 'description': 'travis-ansible-instance', 'id': 'sg-2ze1hhyn7tac4p85gh13', 'name': 'travis-ansible-instance'}
group_id
None
None
Deprecated from version 1.3.1 and replaced by 'id'.

id
string
when present
ID of the security group.

Sample:
sd-safhi3gsv
name
string
when present
Name of the security group.

Sample:
new-group
vpc_id
string
when present
ID of the VPC to which the security group belongs

Sample:
vpc-snif3g3iv


Status

This module is flagged as deprecated and will be removed in version 1.5.0. For more information see DEPRECATED.

Author

  • He Guimin (@xiaozhu36)

Hint

If you notice any issues in this documentation you can edit this document to improve it.