Managing security groups
Security groups are the firewalls that can be used to allow or disallow the flow of traffic. They can be applied to virtual machines. Security groups and virtual machines have a many-to-many relationship. A single security group can be applied to multiple virtual machines and a single virtual machine can have multiple security groups.
How to do it…
- Let's create a security group as follows:
- name: create a security group for web servers os_security_group: name: web-sg state: present description: security group for web servers
The name
parameter has to be unique. The description
parameter is optional, but we recommend using it to state the purpose of the security group. The preceding task will create a security group for us, but there are no rules attached to it. A firewall without any rules is of little use. So let's go ahead and add a rule to allow access to port 80
as follows:
- name: allow port 80 for http os_security_group_rule: security_group...