diff --git a/ci/roles/security_group/tasks/main.yml b/ci/roles/security_group/tasks/main.yml index 5ef8a65f..79a4354e 100644 --- a/ci/roles/security_group/tasks/main.yml +++ b/ci/roles/security_group/tasks/main.yml @@ -72,4 +72,25 @@ name: ansible_security_group state: absent +- name: Create stateless security group + openstack.cloud.security_group: + cloud: "{{ cloud }}" + name: ansible_security_group_stateless + stateful: false + state: present + description: 'Created from Ansible playbook' + register: security_group_stateless + +- name: Assert return values of security_group module + assert: + that: + - security_group_stateless.security_group.name == 'ansible_security_group_stateless' + - security_group_stateless.security_group.stateful == False + +- name: Delete stateless security group + openstack.cloud.security_group: + cloud: "{{ cloud }}" + name: ansible_security_group_stateless + state: absent + - include_tasks: rules.yml diff --git a/plugins/modules/security_group.py b/plugins/modules/security_group.py index 5c01f768..2196e8fa 100644 --- a/plugins/modules/security_group.py +++ b/plugins/modules/security_group.py @@ -113,6 +113,10 @@ options: choices: [present, absent] default: present type: str + stateful: + description: + - Should the resource be stateful or stateless. + type: bool extends_documentation_fragment: - openstack.cloud.openstack ''' @@ -201,6 +205,14 @@ EXAMPLES = r''' name: foo description: security group for foo servers +- name: Create a stateless security group + openstack.cloud.security_group: + cloud: mordred + state: present + stateful: false + name: foo + description: stateless security group for foo servers + - name: Update the existing 'foo' security group description openstack.cloud.security_group: cloud: mordred @@ -260,6 +272,7 @@ class SecurityGroupModule(OpenStackModule): ), ), state=dict(default='present', choices=['absent', 'present']), + stateful=dict(type="bool"), ) module_kwargs = dict( @@ -405,7 +418,7 @@ class SecurityGroupModule(OpenStackModule): def _create(self): kwargs = dict((k, self.params[k]) - for k in ['description', 'name'] + for k in ['description', 'name', 'stateful'] if self.params[k] is not None) project_name_or_id = self.params['project']