Coder Social home page Coder Social logo

ansible-role-mongodb's Introduction

Ansible role for MongoDB

Centos Debian Ubuntu Amazon Linux 2

Ansible role to install and manage MongoDB.

  • Install and configure the MongoDB
  • Configure mongodb users
  • Configure authentication
  • Configure replication
  • Setup MMS automation agent;

MongoDB support matrix:

Distribution < MongoDB 3.4 MongoDB 3.6 MongoDB 4.0 MongoDB 4.2 MongoDB 4.4
Ubuntu 16.04
Ubuntu 18.04
Ubuntu 20.04
Debian 9.x
Debian 10.x
RHEL 7.x
RHEL 8.x
Amazon Linux 2
  • ✅ - fully tested
  • ❌ - don't have official support
  • ⛔ - MongoDB has reached EOL

Variables

# This variable is used to set source of MongoDB installation.
# 'mongodb' - version provided by Debian-based distributions from their official package repositories.
# 'mongodb-org' - version provided by MongoDB package repository.
# 'mongodb' is not included in th role test matrix and working of it is not guarantied.
mongodb_package: mongodb-org

# `mongodb_version` variable sets version of MongoDB.
# Should be '3.6', '4.0', '4.2' or '4.4'. This role doesn't support MongoDB < 3.6.
# I would recommend you to use the latest version of MongoDB.
mongodb_version: "4.4"

mongodb_pymongo_from_pip: true # Install latest PyMongo via PIP or package manager
mongodb_pymongo_pip_version: 3.6.1 # Choose PyMong version to install from pip. If not set use latest
mongodb_user_update_password: "on_create" # MongoDB user password update default policy
mongodb_manage_service: true
mongodb_manage_systemd_unit: true

# Disable transparent hugepages on systemd debian based installations
mongodb_disable_transparent_hugepages: false

# You can enable or disable NUMA support
mongodb_use_numa: true

mongodb_user: "{{ 'mongod' if ('RedHat' == ansible_os_family) else 'mongodb' }}"
mongodb_uid:
mongodb_gid:
mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_package) else 'mongodb' }}"
## net Options
mongodb_net_bindip: 127.0.0.1 # Comma separated list of ip addresses to listen on
mongodb_net_http_enabled: false # Enable http interface
mongodb_net_ipv6: false # Enable IPv6 support (disabled by default)
mongodb_net_maxconns: 65536 # Max number of simultaneous connections
mongodb_net_port: 27017 # Specify port number

## processManagement Options
mongodb_processmanagement_fork: false # Fork server process

## security Options
# Disable or enable security. Possible values: 'disabled', 'enabled'
mongodb_security_authorization: "disabled"
mongodb_security_keyfile: /etc/mongodb-keyfile # Specify path to keyfile with password for inter-process authentication

## storage Options
mongodb_storage_dbpath: /data/db # Directory for datafiles
mongodb_storage_dirperdb: false # Use one directory per DB

# The storage engine for the mongod database
mongodb_storage_engine: "wiredTiger"
# mmapv1 specific options
mongodb_storage_quota_enforced: false # Limits each database to a certain number of files
mongodb_storage_quota_maxfiles: 8 # Number of quota files per DB
mongodb_storage_smallfiles: false # Very useful for non-data nodes

mongodb_storage_journal_enabled: true # Enable journaling
mongodb_storage_prealloc: true # Disable data file preallocation

# WiredTiger Options
mongodb_wiredtiger_cache_size: 1 # Cache size for wiredTiger in GB

## systemLog Options
## The destination to which MongoDB sends all log output. Specify either 'file' or 'syslog'.
## If you specify 'file', you must also specify mongodb_systemlog_path.
mongodb_systemlog_destination: "file"
mongodb_systemlog_logappend: true # Append to logpath instead of over-writing
mongodb_systemlog_path: /var/log/mongodb/{{ mongodb_daemon_name }}.log # Log file to send write to instead of stdout

## replication Options
mongodb_replication_replset: # Enable replication <setname>[/<optionalseedhostlist>]
mongodb_replication_replindexprefetch: "all" # specify index prefetching behavior (if secondary) [none|_id_only|all]
mongodb_replication_oplogsize: 1024 # specifies a maximum size in megabytes for the replication operation log

## setParameter options
# Configure setParameter option.
# Example :
mongodb_set_parameters:
  {
    "enableLocalhostAuthBypass": "true",
    "authenticationMechanisms": "SCRAM-SHA-1,MONGODB-CR",
  }

## Extend config with arbitrary values
# Example :
mongodb_config:
  replication:
    - "enableMajorityReadConcern: false"

# MMS Agent
mongodb_mms_agent_pkg: https://cloud.mongodb.com/download/agent/monitoring/mongodb-mms-monitoring-agent_7.2.0.488-1_amd64.ubuntu1604.deb
mongodb_mms_group_id: ""
mongodb_mms_api_key: ""
mongodb_mms_base_url: https://mms.mongodb.com

# Log rotation
mongodb_logrotate: true # Rotate mongodb logs.
mongodb_logrotate_options:
  - compress
  - copytruncate
  - daily
  - dateext
  - rotate 7
  - size 10M

# password for inter-process authentication
# please regenerate this file on production environment with command 'openssl rand -base64 741'
mongodb_keyfile_content: |
  8pYcxvCqoe89kcp33KuTtKVf5MoHGEFjTnudrq5BosvWRoIxLowmdjrmUpVfAivh
  CHjqM6w0zVBytAxH1lW+7teMYe6eDn2S/O/1YlRRiW57bWU3zjliW3VdguJar5i9
  Z+1a8lI+0S9pWynbv9+Ao0aXFjSJYVxAm/w7DJbVRGcPhsPmExiSBDw8szfQ8PAU
  2hwRl7nqPZZMMR+uQThg/zV9rOzHJmkqZtsO4UJSilG9euLCYrzW2hdoPuCrEDhu
  Vsi5+nwAgYR9dP2oWkmGN1dwRe0ixSIM2UzFgpaXZaMOG6VztmFrlVXh8oFDRGM0
  cGrFHcnGF7oUGfWnI2Cekngk64dHA2qD7WxXPbQ/svn9EfTY5aPw5lXzKA87Ds8p
  KHVFUYvmA6wVsxb/riGLwc+XZlb6M9gqHn1XSpsnYRjF6UzfRcRR2WyCxLZELaqu
  iKxLKB5FYqMBH7Sqg3qBCtE53vZ7T1nefq5RFzmykviYP63Uhu/A2EQatrMnaFPl
  TTG5CaPjob45CBSyMrheYRWKqxdWN93BTgiTW7p0U6RB0/OCUbsVX6IG3I9N8Uqt
  l8Kc+7aOmtUqFkwo8w30prIOjStMrokxNsuK9KTUiPu2cj7gwYQ574vV3hQvQPAr
  hhb9ohKr0zoPQt31iTj0FDkJzPepeuzqeq8F51HB56RZKpXdRTfY8G6OaOT68cV5
  vP1O6T/okFKrl41FQ3CyYN5eRHyRTK99zTytrjoP2EbtIZ18z+bg/angRHYNzbgk
  lc3jpiGzs1ZWHD0nxOmHCMhU4usEcFbV6FlOxzlwrsEhHkeiununlCsNHatiDgzp
  ZWLnP/mXKV992/Jhu0Z577DHlh+3JIYx0PceB9yzACJ8MNARHF7QpBkhtuGMGZpF
  T+c73exupZFxItXs1Bnhe3djgE3MKKyYvxNUIbcTJoe7nhVMrwO/7lBSpVLvC4p3
  wR700U0LDaGGQpslGtiE56SemgoP

# names and passwords for administrative users
mongodb_user_admin_name: siteUserAdmin
mongodb_user_admin_password: passw0rd

mongodb_root_admin_name: siteRootAdmin
mongodb_root_admin_password: passw0rd

mongodb_root_backup_name: backupuser
mongodb_root_backup_password: passw0rd

Usage

Add undergreen.mongodb to your roles and set vars in your playbook file.

Example vars for authorization:

mongodb_security_authorization: "enabled"
mongodb_users:
  - {
    name: testUser,
    password: passw0rd,
    roles: readWrite,
    database: app_development
}

Example vars for oplog user:

mongodb_oplog_users:
  - {
    user: oplog,
    password: passw0rd
}

Required vars to change on production:

mongodb_user_admin_password
mongodb_root_admin_password
mongodb_root_backup_password

# if you use replication and authorization
mongodb_security_keyfile

Example vars for replication:

# It's a 'master' node
mongodb_login_host: 192.168.56.2

# mongodb_replication_params should be configured on each replica set node
mongodb_replication_params:
  - {
      host_name: 192.168.56.2,
      host_port: "{{ mongodb_net_port }}",
      host_type: replica,
    }
  # host_type can be replica(default) and arbiter

And inventory file for replica set:

[mongo_master]
192.158.56.2 mongodb_master=True # it is't a really master of MongoDB replica set,
                                 # use this variable for replica set init only
								 # or when master is moved from initial master node

[mongo_replicas]
192.168.56.3
192.168.56.4

[mongo:children]
mongo_master
mongo_replicas

Licensed under the GPLv2 License. See the LICENSE.md file for details.

Feedback, bug-reports, requests, ...

Are welcome!

ansible-role-mongodb's People

Contributors

boutetnico avatar danielwhite avatar davidcaste avatar deimosfr avatar dekhtyarev avatar dluksza avatar duhast avatar ecerulm avatar fllaca avatar fnerdwq avatar ftao avatar ftx avatar gaetanfl avatar hyeoksuhan avatar jsaliba avatar klen avatar memberit avatar mhavas avatar neilime avatar paulopizarro avatar psabhay avatar rapkin avatar rkiyanchuk avatar rohit-gohri avatar shaulfl avatar thiagoalmeidasa avatar undergreen avatar valferon avatar yoransys avatar zeelax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-role-mongodb's Issues

Configuring users before configuring mongod

Hi,
I'm curious why the role sets up users before Mongo gets configured?
I mean the fact auth_initialization.yml tasks are called before Create mongodb user, Configure mongodb, and so on...
In my vision, the mongod should be configured first. Any comments?

I'm confused by this for a few weeks, but it was ok as long as I was setting up single mongo instance. Now I'm setting up a replica set and it fails because auth_initialization.yml tries to connect to a replica set, but mongod instances are not yet configured to run in a replication mode.

msg: unable to connect to database: No replica set members available for replica set name "myRep"

Or I'm doing something wrong?

Port check not working if multiple bind IPs are configured

The port check at the end of auth_initialization.yml fails if the configuration contains something like

mongodb_conf_bind_ip: "{{ ansible_default_ipv4.address }},127.0.0.1"

Error message:

TASK: [greendayonfire.mongodb | wait MongoDB port is listening] *************** 
failed: [ci] => {"elapsed": 300, "failed": true}
msg: Timeout when waiting for 192.168.0.2,127.0.0.1:27017

FATAL: all hosts have already failed -- aborting

This is because it uses the mongodb_conf_bind_ip as host IP for the port check. If the bind IP is a comma separated list, it uses the whole list as address.

On the other hand, the first port check in the same file succeeds because it uses the hard-coded localhost address 127.0.0.1.

Update support matrix?

The MongoDB support matrix at the top of the README shows a cross for Ubuntu 14.04 and Ubuntu 12.04 for Mongo 3.4. But below that in the config example it says:

I will recommend you to use latest version of MongoDB.
mongodb_version: "3.4"

Is Mongo 3.4 properly tested on Ubuntu 14 and 12? If so, does the grid need updating?

Ansible V2 meta info

In V2 ansible complains version tag in meta/main.yml

Is it possible to remove it ?

MongoDB service name

In Ubuntu 16 LTS when I have installed "mongodb-org" packages my MongoDB service name is called "mongodb" not "mongod".

Tags

Hi,

It would be great to have tags on the playbook like:


---

- include: install.deb.yml
  when: ansible_os_family == 'Debian'
  tags: [mongodb, mongodb-debian]

- include: configure.yml
    tags: [mongodb]

- include: replication.yml
  when: mongodb_conf_replSet != ""
  tags: [mongodb, mongodb-replication]

- include: mms-agent.yml
  when: mongodb_mms_api_key != ""
  tags: [mongodb, mongodb-mms]

This is simpler and quicker to perform tests and deploy only mongo instead of the whole playbook.
What do you think ?

sudo

some, but not all of the tasks require sudo. is the expectation that this role be with a user with su privileges?

Error creating replica set

Hi, I'm having a problem setting up a 3-node replica set using this role on Ubuntu 14.04 servers.

The first run, I received these errors:

TASK: [greendayonfire.mongodb | Replication configuration] ********************
skipping: [db-2] => (item={'host_port': u'27017', 'host_type': 'replica', 'host_name': u'<dedacted ip 2>'})
skipping: [db-3] => (item={'host_port': u'27017', 'host_type': 'replica', 'host_name': u'<dedacted ip 3>'})
failed: [db-1] => (item={'host_port': u'27017', 'host_type': 'replica', 'host_name': u'<dedacted ip 1>'}) => {"failed": true, "item": {"host_name": "<dedacted ip 1>", "host_port": "27017", "host_type": "replica"}}
msg: Unable to initiate replica set: command SON([('authenticate', 1), ('user', u'root'), ('nonce', u'<dedacted>'), ('key', u'<dedacted>')]) failed: auth failed
...ignoring

---

TASK: [greendayonfire.mongodb | Replication configuration] ********************
failed: [db-3] => (item={'host_port': u'27017', 'host_type': 'replica', 'host_name': u'<dedacted ip 3>'}) => {"failed": true, "item": {"host_name": "<dedacted ip 3>", "host_port": "27017", "host_type": "replica"}}
msg: Unable to initiate replica set: command SON([('authenticate', 1), ('user', u'root'), ('nonce', u'<dedacted>'), ('key', u'<dedacted>')]) failed: auth failed
failed: [db-2] => (item={'host_port': u'27017', 'host_type': 'replica', 'host_name': u'<dedacted ip 2>'}) => {"failed": true, "item": {"host_name": "<dedacted ip 2>", "host_port": "27017", "host_type": "replica"}}
msg: Unable to initiate replica set: command SON([('authenticate', 1), ('user', u'root'), ('nonce', u'<dedacted>'), ('key', u'<dedacted>')]) failed: auth failed
ok: [db-1] => (item={'host_port': u'27017', 'host_type': 'replica', 'host_name': u'<dedacted ip 1>'})

In subsequent runs, I got these:

TASK: [greendayonfire.mongodb | Replication configuration] ********************
failed: [db-2] => (item={'host_port': u'27017', 'host_type': 'replica', 'host_name': u'<dedacted ip 2>'}) => {"failed": true, "item": {"host_name": "<dedacted ip 2>", "host_port": "27017", "host_type": "replica"}}
msg: Unable to initiate replica set: command SON([('authenticate', 1), ('user', u'root'), ('nonce', u'<dedacted>'), ('key', u'<dedacted>')]) failed: auth failed
failed: [db-3] => (item={'host_port': u'27017', 'host_type': 'replica', 'host_name': u'<dedacted ip 3>'}) => {"failed": true, "item": {"host_name": "<dedacted ip 3>", "host_port": "27017", "host_type": "replica"}}
msg: Unable to initiate replica set: command SON([('authenticate', 1), ('user', u'root'), ('nonce', u'<dedacted>'), ('key', u'<dedacted>')]) failed: auth failed
ok: [db-1] => (item={'host_port': u'27017', 'host_type': 'replica', 'host_name': u'<dedacted ip 1>'})

When I ssh to db-1 (the master), I can connect to the Mongo shell by supplying the root credentials (configured as part of this role). I also noticed that db-1 is a PRIMARY. However, login and connect the Mongo shell of db-2 and db-3 would result in an auth error.

Below is my role configuration (those with default values are omitted):

mongodb_conf_auth: true
mongodb_conf_bind_ip: 0.0.0.0

mongodb_conf_replSet: myrs
mongodb_replication_params:
  - host_name: "{{ hostvars[inventory_hostname].ansible_eth0_1.ipv4.address }}" # private IP of the server
    host_port: "{{ mongodb_conf_port }}"
    host_type: replica

mongodb_root_admin_name: root
mongodb_root_admin_password: pwd
mongodb_user_admin_name: admin
mongodb_user_admin_password: pwd
mongodb_users:
  - {
    name: buu,
    password: pwd,
    roles: readWrite,
    database: mydb
}
mongodb_keyfile_content: |
  <dedacted key file content>

# the below is only set for db-1 group
mongodb_master: true

Any help is much appreciated.

mongo2 and mongo3 fail when mongo_* targets are run independently

Hello Sergei. I am just learning Ansible and MongoDB and using your great role. I have a problem with it though. When I run:

ansible-playbook site.yml target=mongo_master

and then:

ansible-playbook site.yml target=mongo_replicas

mongo2 and mongo3 fail in the second invocation.

When I run:

ansible-playbook site.yml target=mongo:children

All is fine.

Something is not persisting between individual runs of targets.

I get the error ansible_default_ipv4 is not in the dictionary in the second target.

User creation fail for the first run

Hi,

I encounter an issue when running user creation for the first time:

TASK: [ansible-role-mongodb | create administrative user siteRootAdmin port=yes] *** 
skipping: [vm] => (item={'password': u'test', 'name': u'siteRootAdmin', 'roles': 'root'})

TASK: [ansible-role-mongodb | create administrative user siteUserAdmin port=yes] *** 
skipping: [vm] => (item={'password': u'test', 'name': u'siteUserAdmin', 'roles': 'userAdminAnyDatabase'})

TASK: [ansible-role-mongodb | create normal users] **************************** 
skipping: [vm] => (item={'password': 'test', 'name': 'test', 'roles': 'readWrite', 'database': 'test'})

TASK: [ansible-role-mongodb | create administrative user siteRootAdmin] ******* 
failed: [vm] => (item={'password': u'test', 'name': u'siteRootAdmin', 'roles': 'root'}) => {"failed": true, "item": {"name": "siteRootAdmin", "password": "test", "roles": "root"}}
msg: unable to connect to database: [Errno 111] Connection refused

FATAL: all hosts have already failed -- aborting

If I relaunch the playbook just after, it works:

TASK: [ansible-role-mongodb | create administrative user siteRootAdmin port=yes] *** 
skipping: [vm] => (item={'password': u'test', 'name': u'siteRootAdmin', 'roles': 'root'})

TASK: [ansible-role-mongodb | create administrative user siteUserAdmin port=yes] *** 
skipping: [vm] => (item={'password': u'test', 'name': u'siteUserAdmin', 'roles': 'userAdminAnyDatabase'})

TASK: [ansible-role-mongodb | create normal users] **************************** 
skipping: [vm] => (item={'password': 'test', 'name': 'test', 'roles': 'readWrite', 'database': 'test'})

TASK: [ansible-role-mongodb | create administrative user siteRootAdmin] ******* 
changed: [vm] => (item={'password': u'test', 'name': u'siteRootAdmin', 'roles': 'root'})

TASK: [ansible-role-mongodb | create administrative user siteUserAdmin] ******* 
changed: [vm] => (item={'password': u'test', 'name': u'siteUserAdmin', 'roles': 'userAdminAnyDatabase'})

TASK: [ansible-role-mongodb | create normal users] **************************** 
changed: [vm] => (item={'password': 'test', 'name': 'test', 'roles': 'readWrite', 'database': 'test'})

Any idea ?

Thanks

fail to create first user when auth enabled

Using mongodb 3.2.9, https://github.com/UnderGreen/ansible-role-mongodb/blob/master/library/mongodb_user.py fails on the call to user_find when trying to add the first admin user (since you can't list users before you've added the first admin).

One solution might be to have user_find return false if it throws an exception (that's what I've done to get past this); however, if you want to preserve the exception in user_find, then perhaps you could catch the exception at line 334 uinfo = user_find(client, user, db_name), and allow it to proceed with uinfo = False if db_name is admin.

wait_for used with multiple hosts

http://docs.ansible.com/ansible/wait_for_module.html states that host only takes one host.

In

wait_for: host="{{ mongodb_conf_bind_ip }}" port="{{ mongodb_conf_port }}" delay=5 state=started
, it is passed mongodb_conf_bind_ip which can be multiple according to
mongodb_conf_bind_ip: 127.0.0.1 # Comma separated list of ip addresses to listen on

Ansible complains about duplicate 'when' key in replication_init_auth.yml

Ansible complains about duplicate 'when' key. It then only uses the last defined value.

[WARNING]: While constructing a mapping from
/home/david/devel/ansible/playbooks/roles/dgilo.greendayonfire.mongodb/tasks/replication_init_auth.yml, line 23, column
3, found a duplicate dict key (when).  Using last defined value only.
- name: Replication configuration
  mongodb_replication:
    login_host: "{{ mongodb_login_host|default('localhost') }}"
    login_port: "{{ mongodb_conf_port|default(27017) }}"
    login_user: "{{ mongodb_root_admin_name }}"
    login_password: "{{ mongodb_root_admin_password }}"
    replica_set: "{{ mongodb_conf_replSet }}"
    host_name: "{{ item.host_name }}"
    host_port: "{{ item.host_port|default(27017) }}"
    host_type: "{{ item.host_type|default('replica') }}"
    hidden: "{{ item.hidden|default(false) }}"
    priority: "{{ item.priority|default(1.0) }}"
  when: mongodb_replication_params is defined
  with_items:
    - "{{ mongodb_replication_params|default([]) }}"
  when: mongodb_replica_init|failed

Ansible version:

david@dgilo:~/devel/ansible/playbooks/roles$ ansible --version
ansible 2.1.0 (devel edab8d338d) last updated 2016/04/06 14:56:43 (GMT +200)
  lib/ansible/modules/core: (detached HEAD cf01087a30) last updated 2016/04/05 12:01:07 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD 204b4bab56) last updated 2016/04/05 12:01:07 (GMT +200)
  config file = 
  configured module search path = Default w/o overrides

Error with ansible v2.0.0-0.4.beta2

I just tried to do the provisonning of my vagrant VM with the new beta version of ansible (v2.0.0-0.4.beta2) and it failed.

First, ansible failed with this error:

ERROR! 'version' is not a valid attribute for a RoleMetadata

The error appears to have been in '/etc/ansible/roles/greendayonfire.mongodb/meta/main.yml': line 3, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

I commented the line 3 of the /etc/ansible/roles/greendayonfire.mongodb/meta/main.yml file to skip this problem and retry the operation.

It now fails on "Replication configuration" task with this error:

TASK [greendayonfire.mongodb : Replication configuration] **********************
fatal: [local.myapp.test]: FAILED! => {"failed": true, "msg": "ERROR! 'mongodb_replication_params' is undefined"}

I used the 1.4.6 version of ansible-role-mongodb.

Check of whether systemd is running gives wrong result

Using Ubuntu 15.10, which has systemd by default.

In install.deb.yml:

- name: Check if running on systemd
  command: cat /proc/1/cmdline
  register: systemd
  changed_when: false

The check of whether systemd is running uses the command "cat /proc/1/cmdline". This command in Ubuntu 15.10 gives the result "/sbin/init", which says nothing about systemd. The correct command would be "stat /proc/1/exe" which gives the following output:

vagrant@vagrant-ubuntu-wily-64:~$ sudo stat /proc/1/exe
  File: ‘/proc/1/exe’ -> ‘/lib/systemd/systemd’
  Size: 0               Blocks: 0          IO Block: 1024   symbolic link
Device: 4h/4d   Inode: 36495       Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-04-07 10:21:38.438072106 +0000
Modify: 2016-04-07 10:21:38.402072106 +0000
Change: 2016-04-07 10:21:38.402072106 +0000
 Birth: -

With this change the "reload systemd" handler fails, as there's no "stat" in systemd register.

Dynamic host name

Hi, I looked at your example to define mongodb_replication_params. In my case, DB servers are provisioned dynamically in the playbook, so I can't hard-code the IPs. However, it looks like host_name expects the IP of the current host. If that's the case, can I use ansible_eth0.ipv4.address inside the playbook instead? In other words, the definition would be:

mongodb_replication_params:
  - host_name: "{{ ansible_eth0.ipv4.address }}"
    host_port: "{{ mongodb_conf_port }}"
    host_type: replica

Is it the correct usage or do I misunderstand what host_name expects?

CentOS/RHEL Support Release

Hi, I was wondering when the next release is expected to be?

At the moment our Ansible Galaxy requirements YML file has a direct reference to origin/master which is quite risky since it's essentially a moving version. I see the latest release is v2.1.0 from June, but new features / bugfixes have been introduced since then.

Our YML file looks like this:

- src: https://github.com/UnderGreen/ansible-role-mongodb
  version: origin/master

Thanks in advance,
Justin

exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating

System Details:
[root@mongo03 ~]# hostnamectl
Static hostname: mongo03.ubernet.local
Transient hostname: mongo03
Icon name: computer
Machine ID: e092cc00cc8b41be85aed1b37e13451b
Boot ID: 31abfb07c6d64efba15142e7aefea271
Virtualization: xen
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-693.11.1.el7.x86_64
Architecture: x86-64
[root@mongo03 ~]#

This fixes the issue: chcon -R --reference=/var/lib/mongo /data/db

https://stackoverflow.com/questions/42446931/mongodb-exception-in-initandlisten-20-attempted-to-create-a-lock-file-on-a-rea

A slightly different problem creating a replica set - ServerSelectionTimeoutError

I am using greendayonfire.mongodb with only changes to the variables in defaults/main.yml. When trying to create a replica set I get the following see the following:
error_msg.txt

=============== BEGIN ===============
TASK [greendayonfire.mongodb : Ensure service is started] **********************
ok: [xxx.xxx.xxx.250]

ok: [xxx.xxx.xxx.81]
ok: [xxx.xxx.xxx.111]

TASK [greendayonfire.mongodb : Set fact about wait_for host address] ***********
skipping: [xxx.xxx.xxx.111]
skipping: [xxx.xxx.xxx.81]
skipping: [xxx.xxx.xxx.250]

TASK [greendayonfire.mongodb : Wait when mongodb is started] *******************
ok: [xxx.xxx.xxx.81]
ok: [xxx.xxx.xxx.250]
ok: [xxx.xxx.xxx.111]

TASK [greendayonfire.mongodb : Include replication and auth configuration] *****
skipping: [xxx.xxx.xxx.111]
skipping: [xxx.xxx.xxx.81]
skipping: [xxx.xxx.xxx.250]

TASK [greendayonfire.mongodb : Include replication configuration] **************
included: /Users/your_name_here/Documents/DataScience/finalproj/roles/greendayonfire.mongodb/tasks/replication.yml for xxx.xxx.xxx.111, xxx.xxx.xxx.81, xxx.xxx.xxx.250

TASK [greendayonfire.mongodb : Replication configuration] **********************
skipping: [xxx.xxx.xxx.81] => (item={u'host_port': 27017, u'host_type': u'replica', u'host_name': u'xxx.xxx.xxx.81'})
skipping: [xxx.xxx.xxx.111] => (item={u'host_port': 27017, u'host_type': u'replica', u'host_name': u'xxx.xxx.xxx.81'})
skipping: [xxx.xxx.xxx.250] => (item={u'host_port': 27017, u'host_type': u'replica', u'host_name': u'xxx.xxx.xxx.81'})
skipping: [xxx.xxx.xxx.81] => (item={u'host_port': 27017, u'host_type': u'arbiter', u'host_name': u'xxx.xxx.xxx.250'})
skipping: [xxx.xxx.xxx.111] => (item={u'host_port': 27017, u'host_type': u'arbiter', u'host_name': u'xxx.xxx.xxx.250'})
skipping: [xxx.xxx.xxx.250] => (item={u'host_port': 27017, u'host_type': u'arbiter', u'host_name': u'xxx.xxx.xxx.250'})

TASK [greendayonfire.mongodb : Replication configuration without auth] *********
failed: [xxx.xxx.xxx.81](item={u'host_port': 27017, u'host_type': u'replica', u'host_name': u'xxx.xxx.xxx.81'}) => {"failed": true, "item": {"host_name": "xxx.xxx.xxx.81", "host_port": 27017, "host_type": "replica"}, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n File "/tmp/ansible_z9H610/ansible_module_mongodb_replication.py", line 410, in \r\n main()\r\n File "/tmp/ansible_z9H610/ansible_module_mongodb_replication.py", line 373, in main\r\n client['admin'].command('replSetInitiate', config)\r\n File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line 478, in command\r\n with client._socket_for_reads(read_preference) as (sock_info, slave_ok):\r\n File "/usr/lib/python2.7/contextlib.py", line 17, in enter\r\n return self.gen.next()\r\n File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 798, in _socket_for_reads\r\n with self._get_socket(read_preference) as sock_info:\r\n File "/usr/lib/python2.7/contextlib.py", line 17, in enter\r\n return self.gen.next()\r\n File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 762, in _get_socket\r\n server = self._get_topology().select_server(selector)\r\n File "/usr/local/lib/python2.7/dist-packages/pymongo/topology.py", line 210, in select_server\r\n address))\r\n File "/usr/local/lib/python2.7/dist-packages/pymongo/topology.py", line 186, in select_servers\r\n self._error_message(selector))\r\npymongo.errors.ServerSelectionTimeoutError: xxx.xxx.xxx.111:27017: timed out\r\n", "msg": "MODULE FAILURE", "parsed": false}
failed: [xxx.xxx.xxx.250](item={u'host_port': 27017, u'host_type': u'replica', u'host_name': u'xxx.xxx.xxx.81'}) => {"failed": true, "item": {"host_name": "xxx.xxx.xxx.81", "host_port": 27017, "host_type": "replica"}, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n File "/tmp/ansible_b7AAzE/ansible_module_mongodb_replication.py", line 410, in \r\n main()\r\n File "/tmp/ansible_b7AAzE/ansible_module_mo
=============== BEGIN ===============

To get the replica set configured I have the following in defaults/main.yml
defaults_main.yml.txt

## replication Options
mongodb_replication_replset: "rs0" # Enable replication [/]
mongodb_replication_replindexprefetch: "all" # specify index prefetching behavior (if secondary) [none|_id_only|all]
mongodb_replication_oplogsize: 1024 # specifies a maximum size in megabytes for the replication operation log

# It's a 'master' node
mongodb_login_host: xxx.xxx.xxx.111

# mongodb_replication_params should be configured on each replica set node
mongodb_replication_params:
  • { host_name: "xxx.xxx.xxx.81", host_port: "{{ mongodb_net_port }}", host_type: replica }
  • { host_name: "xxx.xxx.xxx.250", host_port: "{{ mongodb_net_port }}", host_type: arbiter }

    host_type can be replica(default) and arbiter

My inventory.txt file is as follows:
[mongo_master]
xxx.xxx.xxx.111 mongodb_master=True # it is't a really master of MongoDB replica set,
# use this variable for replica set init only
# or when master is moved from initial master node

[mongo_replicas]
xxx.xxx.xxx.81
xxx.xxx.xxx.250

[mongo:children]
mongo_master
mongo_replicas

Everything else is working great! Any help or just pointing me in the right direction would be wonderful!!

Thanks,

David

creation users point to wrong ip

Variable mongodb_net_bindip is set in group variables and mongo really starts listening on this ip.
mongodb_net_bindip: 192.168.X.X

When users creating via mongo_init_user_name variable, then if disable no_log in according task in auth_initialization.yml there is such log:

changed: [mongo01] => (item={u'password': u'XXX', u'name': u'XXX', u'roles': u'root'}) => {
    "changed": true, 
    "invocation": {
        "module_args": {
            "database": "admin", 
            "login_database": null, 
            "login_host": "localhost",
            "login_password": null, 
            "login_port": "27017", 
            "login_user": null, 
            "name": "XXX", 
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "replica_set": null, 
            "roles": [
                "root"
            ], 
            "ssl": false, 
            "ssl_cert_reqs": "CERT_REQUIRED", 
            "state": "present", 
            "update_password": "on_create"
        }
    }, 
    "item": {
        "name": "XXX", 
        "password": "XXX", 
        "roles": "root"
    }, 
    "user": "XXXX"
}

So connection at the moment of user creation trying to reach localhost instead of mongodb_net_bindip: 192.168.X.X

Additional mongod.conf properties

I would like the following properties supported in the mongod.conf file. Please suggest if it would be ok to add these or if there is any issue adding them as configuration options.

  • rest
  • pidfilepath
  • profile
  • directoryperdb

Fail to use SYSLOG

env: Ubuntu 16.04

Log configuration in all.yml
mongodb_systemlog_destination: "syslog" only

Error message When running the playboolk

"msg": "The conditional check '( logfile_stat is defined and not logfile_stat.stat.exists and mongodb_systemlog_destination == "file" )' failed. The error was: error while evaluating conditional (( logfile_stat is defined and not logfile_stat.stat.exists and mongodb_systemlog_destination == "file" )): 'dict object' has no attribute 'stat'\n\nThe error appears to have been in '/home/vagrant/.ansible/roles/greendayonfire.mongodb/tasks/configure.yml': line 33, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Create log if missing\n ^ here\n"}

mongod.conf file

systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log

Not authorized for insert on admin.system.users

The error happens when is provisioned by the second time.
I Did a previous research but I got nothing, so I would appreciate some help :)
The playbook is running using Vagrant with Ubuntu Trusty as OS.

......

TASK: [greendayonfire.mongodb | wait MongoDB port is listening] ***************
ok: [default]

TASK: [greendayonfire.mongodb | create administrative user siteUserAdmin port=yes] ***
ok: [default] => (item={'password': u'NmL6@Rjs', 'name': u'mongoAdmin', 'roles': 'userAdminAnyDatabase'})

TASK: [greendayonfire.mongodb | create administrative user siteRootAdmin port=yes] ***
failed: [default] => (item={'password': u'kLx#m$wb@cw', 'name': u'mongoRoot', 'roles': 'root'}) => {"failed": true, "item": {"name": "mongoRoot", "password": "nOffi4sss@d", "roles": "root"}}
msg: not authorized for insert on admin.system.users

FATAL: all hosts have already failed -- aborting
....

The passwords were changed ;)

User creation fail for the second run

Hi,

I encounter another issue with user creation. It works well on the first run (but only on the first run):


TASK: [ansible-role-mongodb | create administrative user siteRootAdmin port=yes] *** 
skipping: [vm] => (item={'password': u'test', 'name': u'siteRootAdmin', 'roles': 'root'})

TASK: [ansible-role-mongodb | create administrative user siteUserAdmin port=yes] *** 
skipping: [vm] => (item={'password': u'test', 'name': u'siteUserAdmin', 'roles': 'userAdminAnyDatabase'})

TASK: [ansible-role-mongodb | create normal users] **************************** 
skipping: [vm] => (item={'password': 'test', 'name': 'test', 'roles': 'readWrite', 'database': 'test'})

TASK: [ansible-role-mongodb | create administrative user siteRootAdmin] ******* 
changed: [vm] => (item={'password': u'test', 'name': u'siteRootAdmin', 'roles': 'root'})

TASK: [ansible-role-mongodb | create administrative user siteUserAdmin] ******* 
changed: [vm] => (item={'password': u'test', 'name': u'siteUserAdmin', 'roles': 'userAdminAnyDatabase'})

TASK: [ansible-role-mongodb | create normal users] **************************** 
changed: [vm] => (item={'password': 'test', 'name': 'test', 'roles': 'readWrite', 'database': 'test'})

TASK: [ansible-role-mongodb | Create facts.d directory] *********************** 
changed: [vm]

However, it fails on any other ones:

TASK: [ansible-role-mongodb | create administrative user siteRootAdmin port=yes] *** 
changed: [vm] => (item={'password': u'test', 'name': u'siteRootAdmin', 'roles': 'root'})

TASK: [ansible-role-mongodb | create administrative user siteUserAdmin port=yes] *** 
failed: [vm] => (item={'password': u'test', 'name': u'siteUserAdmin', 'roles': 'userAdminAnyDatabase'}) => {"failed": true, "item": {"name": "siteUserAdmin", "password": "test", "roles": "userAdminAnyDatabase"}}
msg: command SON([('createUser', 'siteUserAdmin'), ('pwd', u'5afb56372782697379dc531fb08a69e8'), ('digestPassword', False), ('roles', ['userAdminAnyDatabase']), ('writeConcern', {})]) failed: not authorized on admin to execute command { createUser: "siteUserAdmin", pwd: "xxx", digestPassword: false, roles: [ "userAdminAnyDatabase" ], writeConcern: {} }

FATAL: all hosts have already failed -- aborting

It looks like using different method between both. Any idea about that issue ?

Thanks

Mongo 3

I'm trying to install mongo 3, but with the mongodb_repository variable being defined in vars/ its locked down. Specifying a mongodb_repository value does work:

  roles:
    - role: mongodb
      mongodb_repository: "deb http://repo.mongodb.org/apt/ubuntu {{ansible_distribution_release}}/mongodb-org/3.0 multiverse"

I needed to first comment out the contents of vars/*.yml.

Its not clear to me (ansible newbee) how to make default values that are {{ansible_distribution}} dependent.

Undefined Error in "create administrative user siteUserAdmin"

Using Ansible 2.0.1.0 and ansible-role-mongodb from master, I am having a problem in tasks/auth_initialization.yml line 22.

The error message when reaching this task is:

Skipping task due to undefined Error, in the future this will be a fatal error..

Even if I run my playbook with -vvvvv, I get no further output.

I tried switching from Pymongo 2.9 to 3.2.2 using mongodb_pymongo_pip_version and mongodb_pymongo_from_pip, but it seems to have no effect.

Do you know how I can learn more about this undefined error?

Ansible version requirements

Hi,

I've got an issue when trying to launch your playbook with Ansible 1.7.2 in Debian Jessie package:

ansible-playbook -i hosts site.yml --limit localhost -vvvv
ERROR: mongodb_replication is not a legal parameter in an Ansible task or handler

I tested with pip, and it's the same. However, with 1.8.4 version, it works like a charm. Is there any way to backport the compatibility to 1.7 ?

Note: you should update meta role information

Thanks

New release

Can you please make a new release with latest changes.

Thanks

Replication failing when authentication is enabled

I was trying out your ansible role. I'm running MongoDB 3.4. Everything works like clock work without authentication. But when I enabled authentication it is failing. I did my own debugging and found out this might be because I'm not specifying --authenticationDatabase option. Is there an option to add it to the vars? Thanks in advance.

Error:

failed: [hostname-1] (item={u'host_port': 27017, u'host_type': u'replica', u'host_name': u'hostname-1'}) => {"changed": false, "item": {"host_name": "hostname-1", "host_port": 27017, "host_type": "replica"}, "msg": "Unable to initiate replica set: not authorized on admin to execute command { replSetInitiate: { _id: "clusterName", members: [ { host: "hostname-1:27017", _id: 0 } ] } }"}

How to archive multiple directories (not files) in Ansible

Could some one help me with the play which will archive multiple directories into a abcd.tar ?

Example:
db
lib
bin
Say, the above 3 directories are under /Data/ and I want to archive them ( .tar ) into /Info/abcd.tar
Thank you in advance !!
~ Nagaraj

Amazon RHEL ami has ansible_distribution == RedHat (instead of Red Hat Enterprise Linux)

Amazon RHEL (ami-9fa343e7) has ansible_distribution == RedHat (instead of Red Hat Enterprise Linux). This causes skipping agent download in mms-agent.yml

Original:

  • name: Download MMS Agent (RHEL)
    get_url: url={{mongodb_mms_agent_pkg}} dest={{mongodb_storage_dbpath}}/mms-agent.rpm
    register: mongodb_mms_agent_loaded
    when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'

Fix could be:

  • name: Download MMS Agent (RHEL)
    get_url: url={{mongodb_mms_agent_pkg}} dest={{mongodb_storage_dbpath}}/mms-agent.rpm
    register: mongodb_mms_agent_loaded
    when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'RedHat'

mongodb_replication_params convertation

Hi. I'd like to create a replications from list of groups, that I've defined earlier.
So, let's say, I have a group called groups['mongodb-replica']
How can I pass them to mongodb_replication_params?
Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.