|
1 | 1 | ---
|
| 2 | + |
2 | 3 | - name: Register default MongoDB listen IP
|
3 | 4 | set_fact: mongodb_listen_ip=127.0.0.1
|
4 | 5 | when: ansible_local.mongodb.mongodb.mongodb_listen_ip is undefined
|
|
7 | 8 | set_fact: mongodb_listen_ip={{ ansible_local.mongodb.mongodb.mongodb_listen_ip }}
|
8 | 9 | when: ansible_local.mongodb.mongodb.mongodb_listen_ip is defined
|
9 | 10 |
|
10 |
| - |
11 | 11 | - name: Create keyFile
|
12 | 12 | copy:
|
13 | 13 | dest: "{{ mongodb_conf_keyFile }}"
|
|
23 | 23 |
|
24 | 24 | - name: ensure mongodb started and enabled
|
25 | 25 | service: name={{ mongodb_daemon_name }} state=started enabled=yes
|
26 |
| - when: mongodb_manager_service |
| 26 | + when: mongodb_manage_service |
| 27 | + |
| 28 | +- name: get pid of mongod |
| 29 | + command: pidof mongod |
| 30 | + register: mongod_pid |
| 31 | + ignore_errors: True |
| 32 | + |
| 33 | +- name: temporary start mongod if not started |
| 34 | + command: '/usr/bin/mongod --config /etc/mongod.conf --fork' |
| 35 | + when: mongod_pid.rc != 0 |
27 | 36 |
|
28 | 37 | - name: wait MongoDB port is listening
|
29 | 38 | wait_for: host="{{ mongodb_listen_ip }}" port="{{ mongodb_conf_port }}" delay=10 timeout=60 state=started
|
|
51 | 60 | template: src=mongod.conf.j2 dest=/etc/mongod.conf backup=yes owner=root group=root mode=0644
|
52 | 61 | register: config_result
|
53 | 62 |
|
| 63 | +- name: get pid of mongod |
| 64 | + command: pidof mongod |
| 65 | + register: mongod_new_pid |
| 66 | + when: mongod_pid.rc != 0 |
| 67 | + |
| 68 | +- name: kill temporary mongod if started |
| 69 | + command: kill {{ mongod_new_pid.stdout }} |
| 70 | + when: mongod_pid.rc != 0 |
| 71 | + |
54 | 72 | - name: mongodb restart
|
55 | 73 | service: name={{ mongodb_daemon_name }} state=restarted
|
56 |
| - when: config_result|changed and mongodb_manager_service |
| 74 | + when: config_result|changed and mongodb_manage_service |
0 commit comments