Repository: ansible/ansible

Issue:
[module/ec2_vol] Add cross instance idempotence for ec2 ebs disks
Added a new param to the ec2_vol module `tag_id_name`.
If given it will tag the ebs disk and use that disk again if the instance is terminated



Discussion:
Thanks for this. It's been suggested before but I think we previously declined.

@mpdehaan - I will open a PR on Monday/Tuesday with the changes I have to make it idempotent across all tags via complex args.  I haven't done this yet as I need to rebase on the recent changes by Bruce P but the module worked ok from my limited testing.

Sorry for the delay.  I took at a look at my module changes and they bring some enhancements in device attachment and detection of mapping but the tag stuff is currently broken.  I don't have time to change this so perhaps we merge this now and I come back to it later.  Some of the changes I'm working towards would basically re-write this module. 

Ok sound's good

@lwade is there an update on the status of the ec2_vol module? I'm quite keen to see this feature included. 

@megakorre I'm closing this in favor of https://github.com/ansible/ansible/pull/5287 

Please work with @ebrevdo to test his code once he fixes the merge conflicts.

Great!


Resolving patch:
diff --git a/lib/ansible/modules/database/postgresql/postgresql_user.py b/lib/ansible/modules/database/postgresql/postgresql_user.py
--- a/lib/ansible/modules/database/postgresql/postgresql_user.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_user.py
@@ -334,6 +334,56 @@ def user_alter(cursor, module, user, password, role_attr_flags, encrypted, expir
             if current_role_attrs[i] != new_role_attrs[i]:
                 changed = True
 
+    elif no_password_changes and role_attr_flags != '':
+        # Grab role information from pg_roles instead of pg_authid
+        select = "SELECT * FROM pg_roles where rolname=%(user)s"
+        cursor.execute(select, {"user": user})
+        # Grab current role attributes.
+        current_role_attrs = cursor.fetchone()
+
+        role_attr_flags_changing = False
+
+        if role_attr_flags:
+            role_attr_flags_dict = {}
+            for r in role_attr_flags.split(' '):
+                if r.startswith('NO'):
+                    role_attr_flags_dict[r.replace('NO', '', 1)] = False
+                else:
+                    role_attr_flags_dict[r] = True
+
+            for role_attr_name, role_attr_value in role_attr_flags_dict.items():
+                if current_role_attrs[PRIV_TO_AUTHID_COLUMN[role_attr_name]] != role_attr_value:
+                    role_attr_flags_changing = True
+
+        if not role_attr_flags_changing:
+            return False
+
+        alter = ['ALTER USER %(user)s' % {"user": pg_quote_identifier(user, 'role')}]
+        if role_attr_flags:
+            alter.append('WITH %s' % role_attr_flags)
+
+        try:
+            cursor.execute(' '.join(alter))
+        except psycopg2.InternalError:
+            e = get_exception()
+            if e.pgcode == '25006':
+                # Handle errors due to read-only transactions indicated by pgcode 25006
+                # ERROR:  cannot execute ALTER ROLE in a read-only transaction
+                changed = False
+                module.fail_json(msg=e.pgerror)
+                return changed
+            else:
+                raise psycopg2.InternalError(e)
+
+        # Grab new role attributes.
+        cursor.execute(select, {"user": user})
+        new_role_attrs = cursor.fetchone()
+
+        # Detect any differences between current_ and new_role_attrs.
+        for i in range(len(current_role_attrs)):
+            if current_role_attrs[i] != new_role_attrs[i]:
+                changed = True
+
     return changed
 
 def user_delete(cursor, user):


Test patch: