diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/README.md b/README.md index 934fe74..ce7cc5b 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Ansible role which manage [MongoDB](http://www.mongodb.org/) ```yaml mongodb_package: mongodb-org +mongodb_force_wait_for_port: false # When not forced, the role will wait for mongod port to become available only with systemd mongodb_additional_packages: - python-pymongo diff --git a/defaults/main.yml b/defaults/main.yml index 47d4176..cf63b0f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,7 @@ --- mongodb_package: mongodb-org +mongodb_force_wait_for_port: false mongodb_additional_packages: - python-pymongo diff --git a/tasks/auth_initialization.yml b/tasks/auth_initialization.yml index 9418a4b..f136b7f 100644 --- a/tasks/auth_initialization.yml +++ b/tasks/auth_initialization.yml @@ -9,7 +9,7 @@ name: "{{ item.name }}" password: "{{ item.password }}" roles: "{{ item.roles }}" - login_host: "{{ mongodb_listen_iface }}" + login_host: "{{ mongodb_listen_ip }}" with_items: - { name: "{{ mongodb_user_admin_name }}", @@ -25,7 +25,7 @@ name: "{{ item.name }}" password: "{{ item.password }}" roles: "{{ item.roles }}" - login_host: "{{ mongodb_listen_iface }}" + login_host: "{{ mongodb_listen_ip }}" 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: "{{ mongodb_listen_iface }}" + login_host: "{{ mongodb_listen_ip }}" login_user: "{{ mongodb_user_admin_name }}" login_password: "{{ mongodb_user_admin_password }}" with_items: @@ -52,15 +52,10 @@ when: mongodb_users is defined and ansible_local.mongodb.mongodb.mongodb_login_port is undefined - name: Create facts.d directory - file: - state: directory - recurse: yes - path: /etc/ansible/facts.d + file: path=/etc/ansible/facts.d state=directory recurse=yes 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 }}\nmongodb_listen_iface={{ mongodb_conf_bind_ip }}\n" + template: src=mongodb.fact.j2 dest=/etc/ansible/facts.d/mongodb.fact when: (ansible_local.mongodb.mongodb.mongodb_login_port is undefined) and (rootadmin_user_result|changed or useradmin_user_result|changed or config_result|changed) diff --git a/tasks/auth_initialization_ald.yml b/tasks/auth_initialization_ald.yml index a1c5d70..8960ec5 100644 --- a/tasks/auth_initialization_ald.yml +++ b/tasks/auth_initialization_ald.yml @@ -5,7 +5,7 @@ name: "{{ item.name }}" password: "{{ item.password }}" roles: "{{ item.roles }}" - login_host: "{{ mongodb_listen_iface }}" + login_host: "{{ mongodb_listen_ip }}" login_port: "{{ ansible_local.mongodb.mongodb.mongodb_login_port }}" with_items: - { @@ -20,7 +20,7 @@ name: "{{ item.name }}" password: "{{ item.password }}" roles: "{{ item.roles }}" - login_host: "{{ mongodb_listen_iface }}" + login_host: "{{ mongodb_listen_ip }}" login_port: "{{ ansible_local.mongodb.mongodb.mongodb_login_port }}" login_user: "{{ mongodb_user_admin_name }}" login_password: "{{ mongodb_user_admin_password }}" @@ -38,7 +38,7 @@ password: "{{ item.password }}" roles: "{{ item.roles }}" replica_set: "{{ mongodb_conf_replSet }}" - login_host: "{{ mongodb_listen_iface }}" + login_host: "{{ mongodb_listen_ip }}" login_port: "{{ ansible_local.mongodb.mongodb.mongodb_login_port }}" login_user: "{{ mongodb_user_admin_name }}" login_password: "{{ mongodb_user_admin_password }}" diff --git a/tasks/configure.yml b/tasks/configure.yml index ec28775..d60ea4f 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,11 +1,11 @@ --- -- 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 default MongoDB listen IP + set_fact: mongodb_listen_ip=127.0.0.1 + when: ansible_local.mongodb.mongodb.mongodb_listen_ip 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: Register MongoDB listen IP + set_fact: mongodb_listen_ip={{ ansible_local.mongodb.mongodb.mongodb_listen_ip }} + when: ansible_local.mongodb.mongodb.mongodb_listen_ip is defined - name: Create keyFile @@ -25,8 +25,8 @@ service: name={{ mongodb_daemon_name }} state=started enabled=yes - name: wait MongoDB port is listening - 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? + wait_for: host="{{ mongodb_listen_ip }}" port="{{ mongodb_conf_port }}" delay=10 timeout=60 state=started + when: mongodb_force_wait_for_port or "'systemd' in systemd.stdout" - include: auth_initialization.yml when: mongodb_conf_auth diff --git a/templates/mongodb.fact.j2 b/templates/mongodb.fact.j2 new file mode 100644 index 0000000..00465ba --- /dev/null +++ b/templates/mongodb.fact.j2 @@ -0,0 +1,3 @@ +[mongodb] +mongodb_login_port={{ mongodb_conf_port }} +mongodb_listen_ip={{ mongodb_conf_bind_ip }}