mongodb_user - Adds or removes a user from a MongoDB database.

Author:Elliott Foster

Synopsis

New in version 1.1.

Adds or removes a user from a MongoDB database.

Options

parameter required default choices comments
database yes
    The name of the database to add/remove the user from
    login_host no localhost
      The host running the database
      login_password no
        The password used to authenticate with
        login_port no 27017
          The port to connect to
          login_user no
            The username used to authenticate with
            password no
              The password to use for the user
              replica_set no
                Replica set to connect to (automatically connects to primary for writes) (added in Ansible 1.6)
                roles no readWrite
                  The database user roles valid values are one or more of the following: read, 'readWrite', 'dbAdmin', 'userAdmin', 'clusterAdmin', 'readAnyDatabase', 'readWriteAnyDatabase', 'userAdminAnyDatabase', 'dbAdminAnyDatabase'This param requires mongodb 2.4+ and pymongo 2.5+ (added in Ansible 1.3)
                  state no present
                  • present
                  • absent
                  The database user state
                  user yes
                    The name of the user to add or remove

                    Note

                    Requires pymongo

                    Examples


                    # Create 'burgers' database user with name 'bob' and password '12345'.
                    - mongodb_user: database=burgers name=bob password=12345 state=present
                    
                    # Delete 'burgers' database user with name 'bob'.
                    - mongodb_user: database=burgers name=bob state=absent
                    
                    # Define more users with various specific roles (if not defined, no roles is assigned, and the user will be added via pre mongo 2.2 style)
                    - mongodb_user: database=burgers name=ben password=12345 roles='read' state=present
                    - mongodb_user: database=burgers name=jim password=12345 roles='readWrite,dbAdmin,userAdmin' state=present
                    - mongodb_user: database=burgers name=joe password=12345 roles='readWriteAnyDatabase' state=present
                    
                    # add a user to database in a replica set, the primary server is automatically discovered and written to
                    - mongodb_user: database=burgers name=bob replica_set=blecher password=12345 roles='readWriteAnyDatabase' state=present
                    

                    Note

                    Requires the pymongo Python package on the remote host, version 2.4.2+. This can be installed using pip or the OS package manager. @see http://api.mongodb.org/python/current/installation.html

                    Table Of Contents

                    Previous topic

                    Database Modules

                    Next topic

                    mysql_db - Add or remove MySQL databases from a remote host.