Debian Codegraph @

ansible_collections/community/mongodb/roles/mongodb_auth/README.md

raw
1 mongodb_auth
2 ============
3
4 This role to enables auth on MongoDB servers, adds the first admin user, and adds a list of other users.
5 If your mongo instance requires ssl or an alternative auth_mechanism, please use
6 [`module_defaults`](https://docs.ansible.com/ansible/latest/user_guide/playbooks_module_defaults.html)
7 to provide the default auth details for `community.mongodb.mongodb_user` (these defaults are ignored
8 when adding the initial admin user with the localhost exception).
9
10 By default this role checks and creates a file at `/root/mongodb_admin.success` to provide idempotent creation of the first admin user.
11
12 - If running this on a MongoDB server that already has an admin user (ie when using this role to audit
13 an alternate install method), you must touch the file or you will get an error when this role tries to add the admin user again.
14 - When setting up a fresh MongoDB installation on a system previously configured with this role, remember to delete this file.
15
16 Role Variables
17 --------------
18
19 * `mongod_host`: The domain or ip to use to communicate with mongod. Default localhost.
20 * `mongod_port`: The port used by the mongod process. Default 27017.
21 * `mongod_package`: The mongod package to install. Default mongodb-org-server.
22 * `authorization`: Enable authorization. Default enabled.
23 * `mongodb_admin_db`: MongoDB admin database (for adding users). Default admin.
24 * `mongodb_admin_user`: MongoDB admin username. Default admin.
25 * `mongodb_admin_pwd`: MongoDB admin password. Defaults to value of mongodb_admin_default_pwd.
26 * `mongodb_admin_default_pwd`: MongoDB admin password (for parent roles to override without overriding user's password). Default admin.
27 * `mongodb_users`: List of additional users to add. Each user dict should include fields: db, user, pwd, state (default: "present"), roles (default: "readWrite").
28 * `mongodb_force_update_password`: Whether or not to force a password update for any users in mongodb_users. Setting this to yes will result in 'changed' on every run, even if the password is the same. Setting this to no only adds a password when creating the user.
29 * `mongodb_create_for_localhost_exception`: Path of the file checked before creating the first admin user. If present, it is skipped. If absent, admin is added and the file is created afterwards. Default `/root/mongodb_admin.success`.
30
31 IMPORTANT NOTE: It is expected that mongodb_admin_user & mongodb_admin_pwd values be overridden in your own file protected by Ansible Vault. Any production environments should protect these values. For more information see [Ansible Vault](https://docs.ansible.com/ansible/latest/user_guide/vault.html)
32
33 Dependencies
34 ------------
35
36 mongodb_repository
37
38 Example Playbook
39 ----------------
40
41 Install MongoDB preparing hosts for a Replicaset
42
43 ```yaml
44 - hosts: servers
45 roles:
46 - { role: "community.mongodb.mongodb_repository" }
47 - { role: "community.mongodb.mongodb_mongod" }
48
49 tasks:
50
51 - name: Initialise MongoDB Replicaset rs0
52 community.mongodb.mongodb_replicaset:
53 login_database: "admin"
54 login_host: localhost
55 replica_set: "rs0"
56 members:
57 - "mongodb1"
58 - "mongodb2"
59 - "mongodb3"
60 when: ansible_hostname == "mongodb1"
61 register: repl
62
63 - name: Ensure replicaset has reached a converged state
64 community.mongodb.mongodb_status:
65 replica_set: "rs0"
66 poll: 10
67 interval: 10
68 when: repl.changed == True
69
70 - name: Import mongodb_auth role
71 include_role:
72 name: mongodb_auth
73 vars:
74 mongod_host: "127.0.0.1"
75 mongodb_admin_pwd: "f00b@r"
76 when: ansible_hostname == "mongodb1"
77 ```
78
79 License
80 -------
81
82 BSD
83
84 Author Information
85 ------------------
86
87 Jacob Floyd (https://github.com/cognifloyd)