Configuration and authentication with custom settings fix

This commit is contained in:
Oleg Vivtash 2015-04-04 14:26:31 +03:00
parent 60ec8021ee
commit 84b9f87e56
3 changed files with 31 additions and 15 deletions

View File

@ -9,7 +9,7 @@
name: "{{ item.name }}"
password: "{{ item.password }}"
roles: "{{ item.roles }}"
login_host: 127.0.0.1
login_host: "{{ mongodb_listen_iface }}"
with_items:
- {
name: "{{ mongodb_user_admin_name }}",
@ -25,7 +25,7 @@
name: "{{ item.name }}"
password: "{{ item.password }}"
roles: "{{ item.roles }}"
login_host: 127.0.0.1
login_host: "{{ mongodb_listen_iface }}"
login_user: "{{ mongodb_user_admin_name }}"
login_password: "{{ mongodb_user_admin_password }}"
with_items:
@ -44,7 +44,7 @@
password: "{{ item.password }}"
roles: "{{ item.roles }}"
replica_set: "{{ mongodb_conf_replSet }}"
login_host: 127.0.0.1
login_host: "{{ mongodb_listen_iface }}"
login_user: "{{ mongodb_user_admin_name }}"
login_password: "{{ mongodb_user_admin_password }}"
with_items:
@ -56,10 +56,11 @@
state: directory
recurse: yes
path: /etc/ansible/facts.d
when: rootadmin_user_result|changed or useradmin_user_result|changed
when: (ansible_local.mongodb.mongodb.mongodb_login_port is undefined) and (rootadmin_user_result|changed or useradmin_user_result|changed or config_result|changed)
- name: Create facts file for mongodb
copy:
dest: /etc/ansible/facts.d/mongodb.fact
content: "[mongodb]\nmongodb_login_port={{ mongodb_conf_port }}\n\n"
when: rootadmin_user_result|changed or useradmin_user_result|changed
content: "[mongodb]\nmongodb_login_port={{ mongodb_conf_port }}\nmongodb_listen_iface={{ mongodb_conf_bind_ip }}\n"
when: (ansible_local.mongodb.mongodb.mongodb_login_port is undefined) and (rootadmin_user_result|changed or useradmin_user_result|changed or config_result|changed)

View File

@ -1,10 +1,11 @@
---
- name: create administrative user siteUserAdmin port=yes
mongodb_user:
database: admin
name: "{{ item.name }}"
password: "{{ item.password }}"
roles: "{{ item.roles }}"
login_host: 127.0.0.1
login_host: "{{ mongodb_listen_iface }}"
login_port: "{{ ansible_local.mongodb.mongodb.mongodb_login_port }}"
with_items:
- {
@ -19,7 +20,7 @@
name: "{{ item.name }}"
password: "{{ item.password }}"
roles: "{{ item.roles }}"
login_host: 127.0.0.1
login_host: "{{ mongodb_listen_iface }}"
login_port: "{{ ansible_local.mongodb.mongodb.mongodb_login_port }}"
login_user: "{{ mongodb_user_admin_name }}"
login_password: "{{ mongodb_user_admin_password }}"
@ -30,14 +31,14 @@
roles: "root"
}
- name: create normal users
- name: create normal users port=yes
mongodb_user:
database: "{{ item.database }}"
name: "{{ item.name }}"
password: "{{ item.password }}"
roles: "{{ item.roles }}"
replica_set: "{{ mongodb_conf_replSet }}"
login_host: 127.0.0.1
login_host: "{{ mongodb_listen_iface }}"
login_port: "{{ ansible_local.mongodb.mongodb.mongodb_login_port }}"
login_user: "{{ mongodb_user_admin_name }}"
login_password: "{{ mongodb_user_admin_password }}"

View File

@ -1,4 +1,12 @@
---
- name: Register default MongoDB listen interface
set_fact: mongodb_listen_iface=127.0.0.1
when: ansible_local.mongodb.mongodb.mongodb_listen_iface is undefined
- name: Register MongoDB listen interface
set_fact: mongodb_listen_iface={{ ansible_local.mongodb.mongodb.mongodb_listen_iface }}
when: ansible_local.mongodb.mongodb.mongodb_listen_iface is defined
- name: Create keyFile
copy:
@ -17,8 +25,8 @@
service: name={{ mongodb_daemon_name }} state=started enabled=yes
- name: wait MongoDB port is listening
wait_for: host="{{ mongodb_conf_bind_ip }}"port="{{ mongodb_conf_port }}" delay=10 timeout=60 state=started
when: "'systemd' in systemd.stdout"
wait_for: host="{{ mongodb_listen_iface }}" port="{{ mongodb_conf_port }}" delay=5 timeout=60 state=started
#when: "'systemd' in systemd.stdout" #TODO Why only with systemd?
- include: auth_initialization.yml
when: mongodb_conf_auth
@ -29,11 +37,17 @@
- name: Configure database directory
file: state=directory path={{ mongodb_conf_dbpath }} owner={{mongodb_user}} group={{mongodb_user}} mode=0755
- name: Configure logs
file: state=file path={{ mongodb_conf_logpath }} owner={{mongodb_user}} group={{mongodb_user}} mode=0644
- name: Create log dir if missing
file: state=directory recurse=yes dest={{ mongodb_conf_logpath|dirname }} owner={{ mongodb_user }} group={{mongodb_user}} mode=0755
- name: Create log if missing
file: state=touch dest={{ mongodb_conf_logpath }} owner={{ mongodb_user }} group={{mongodb_user}} mode=0755
- name: Configure log file
file: state=file path={{ mongodb_conf_logpath }} owner={{mongodb_user}} group={{mongodb_user}} mode=0755
- name: Configure mongodb
template: src=mongod.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0644
template: src=mongod.conf.j2 dest=/etc/mongod.conf backup=yes owner=root group=root mode=0644
register: config_result
- name: mongodb restart