add network and storage handling
This commit is contained in:
parent
2e4af03db8
commit
d25eae927d
@ -15,3 +15,20 @@ mongodb_systemlog_path: /var/log/mongodb/mongod.log
|
||||
mongodb_rbac_enabled: True
|
||||
mongodb_user_admin_name: mongoadm
|
||||
mongodb_user_admin_password: secure
|
||||
|
||||
mongodb_lvm_enabled: False
|
||||
# mongodb_lvm_pvs:
|
||||
# - sda
|
||||
# mongodb_lvm_vg: vg_mongo
|
||||
# mongodb_lvm_lv: lv_mongo
|
||||
# mongodb_lvm_size: 10G
|
||||
# mongodb_lvm_fstype: xfs
|
||||
|
||||
mongodb_net_bindip:
|
||||
- 127.0.0.1
|
||||
mongodb_net_http_enabled: False
|
||||
mongodb_net_ipv6_enabled: False
|
||||
mongodb_net_maxconns: 65536
|
||||
mongodb_net_port: 27017
|
||||
|
||||
mongodb_processmanagement_fork_enabled: True
|
||||
|
79
tasks/config.yml
Normal file
79
tasks/config.yml
Normal file
@ -0,0 +1,79 @@
|
||||
---
|
||||
- block:
|
||||
- name: Create system group '{{ mongodb_system_group }}'
|
||||
group:
|
||||
name: "{{ mongodb_system_group }}"
|
||||
gid: "{{ mongodb_system_gid | default(omit) }}"
|
||||
state: present
|
||||
|
||||
- name: Create system user '{{ mongodb_system_user }}'
|
||||
user:
|
||||
name: "{{ mongodb_system_user }}"
|
||||
uid: "{{ mongodb_system_uid | default(omit) }}"
|
||||
group: "{{ mongodb_system_group }}"
|
||||
notify: __mongod_restart
|
||||
|
||||
- name: Create db storage dir '{{ mongodb_storage_dbpath }}'
|
||||
file:
|
||||
path: "{{ mongodb_storage_dbpath }}"
|
||||
owner: "{{ mongodb_system_user }}"
|
||||
group: "{{ mongodb_system_group }}"
|
||||
recurse: yes
|
||||
state: directory
|
||||
|
||||
- name: Create log dir '{{ mongodb_systemlog_path | dirname }}'
|
||||
file:
|
||||
path: "{{ mongodb_systemlog_path | dirname }}"
|
||||
owner: "{{ mongodb_system_user }}"
|
||||
group: "{{ mongodb_system_group }}"
|
||||
recurse: yes
|
||||
state: directory
|
||||
when: mongodb_systemlog_destination == 'file'
|
||||
|
||||
- block:
|
||||
- name: Create volume group 'mongodb_lvm_vg'
|
||||
lvg:
|
||||
vg: "{{ mongodb_lvm_vg }}"
|
||||
pvs: "{{ mongodb_lvm_pvs|join(',') }}"
|
||||
|
||||
- name: Create logical volume 'mongodb_lvm_lv'
|
||||
lvol:
|
||||
vg: "{{ mongodb_lvm_vg }}"
|
||||
lv: "{{ mongodb_lvm_lv }}"
|
||||
size: "{{ mongodb_lvm_size }}"
|
||||
|
||||
- name: Create filesystem for '/dev/mapper/{{ mongodb_lvm_vg }}-{{ mongodb_lvm_lv }}'
|
||||
filesystem:
|
||||
fstype: "{{ mongodb_lvm_fstype }}"
|
||||
dev: "/dev/mapper/{{ mongodb_lvm_vg }}-{{ mongodb_lvm_lv }}"
|
||||
|
||||
- name: Mount volume to 'mongodb_storage_dbpath'
|
||||
mount:
|
||||
path: "{{ mongodb_storage_dbpath }}"
|
||||
src: "/dev/mapper/{{ mongodb_lvm_vg }}-{{ mongodb_lvm_lv }}"
|
||||
fstype: "{{ mongodb_lvm_fstype }}"
|
||||
state: mounted
|
||||
|
||||
- name: Change permissions for mountpoint
|
||||
file:
|
||||
path: "{{ mongodb_storage_dbpath }}"
|
||||
owner: "{{ mongodb_user }}"
|
||||
group: "{{ mongodb_group }}"
|
||||
mode: 0750
|
||||
become: True
|
||||
when: mongodb_lvm_enabled
|
||||
|
||||
- name: Deploy configuration file
|
||||
template:
|
||||
src: etc/mongod.conf.j2
|
||||
dest: /etc/mongod.conf
|
||||
mode: 0644
|
||||
notify: __mongod_restart
|
||||
|
||||
- name: Make sure mongodb is up and running
|
||||
systemd:
|
||||
name: mongod
|
||||
state: started
|
||||
enabled: yes
|
||||
become: True
|
||||
become_user: root
|
@ -23,55 +23,3 @@
|
||||
name: pymongo
|
||||
state: present
|
||||
extra_args: --user
|
||||
|
||||
- block:
|
||||
- name: Create system group '{{ mongodb_system_group }}'
|
||||
group:
|
||||
name: "{{ mongodb_system_group }}"
|
||||
gid: "{{ mongodb_system_gid | default(omit) }}"
|
||||
state: present
|
||||
|
||||
- name: Create system user '{{ mongodb_system_user }}'
|
||||
user:
|
||||
name: "{{ mongodb_system_user }}"
|
||||
uid: "{{ mongodb_system_uid | default(omit) }}"
|
||||
group: "{{ mongodb_system_group }}"
|
||||
notify: __mongod_restart
|
||||
|
||||
- name: Create db storage dir '{{ mongodb_storage_dbpath }}'
|
||||
file:
|
||||
path: "{{ mongodb_storage_dbpath }}"
|
||||
owner: "{{ mongodb_system_user }}"
|
||||
group: "{{ mongodb_system_group }}"
|
||||
recurse: yes
|
||||
state: directory
|
||||
|
||||
- name: Create log dir '{{ mongodb_systemlog_path | dirname }}'
|
||||
file:
|
||||
path: "{{ mongodb_systemlog_path | dirname }}"
|
||||
owner: "{{ mongodb_system_user }}"
|
||||
group: "{{ mongodb_system_group }}"
|
||||
recurse: yes
|
||||
state: directory
|
||||
when: mongodb_systemlog_destination == 'file'
|
||||
|
||||
- name: Deploy configuration file
|
||||
template:
|
||||
src: etc/mongod.conf.j2
|
||||
dest: /etc/mongod.conf
|
||||
mode: 0644
|
||||
notify: __mongod_restart
|
||||
|
||||
- name: Make sure mongodb is up and running
|
||||
systemd:
|
||||
name: mongod
|
||||
state: started
|
||||
enabled: yes
|
||||
become: True
|
||||
become_user: root
|
||||
|
||||
- name: Check where admin user already exists
|
||||
command: |
|
||||
mongo --quiet -u {{ mongodb_user_admin_name }} -p {{ mongodb_user_admin_password }} --eval 'db.version()' admin
|
||||
register: __mongodb_admin_check
|
||||
changed_when: False
|
||||
|
@ -1,4 +1,12 @@
|
||||
---
|
||||
- include_tasks: install.yml
|
||||
- include_tasks: config.yml
|
||||
|
||||
- name: Check where admin user already exists
|
||||
command: |
|
||||
mongo --quiet -u {{ mongodb_user_admin_name }} -p {{ mongodb_user_admin_password }} --eval 'db.version()' admin
|
||||
register: __mongodb_admin_check
|
||||
changed_when: False
|
||||
|
||||
- include_tasks: auth.yml
|
||||
when: not __mongodb_admin_check.rc == 0
|
||||
|
@ -15,27 +15,24 @@ storage:
|
||||
dbPath: {{ mongodb_storage_dbpath }}
|
||||
journal:
|
||||
enabled: {{ mongodb_storage_journal_enabled | lower }}
|
||||
# engine:
|
||||
# mmapv1:
|
||||
# wiredTiger:
|
||||
|
||||
# how the process runs
|
||||
processManagement:
|
||||
fork: true # fork and run in background
|
||||
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
|
||||
fork: {{ mongodb_processmanagement_fork_enabled | lower }}
|
||||
pidFilePath: /var/run/mongodb/mongod.pid
|
||||
timeZoneInfo: /usr/share/zoneinfo
|
||||
|
||||
# network interfaces
|
||||
net:
|
||||
port: 27017
|
||||
bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
|
||||
bindIp: {{ mongodb_net_bindip | join(',') }}
|
||||
{% if mongodb_version | version_compare("3.6", "<") -%}
|
||||
http:
|
||||
enabled: {{ mongodb_net_http_enabled | lower }}
|
||||
{% endif -%}
|
||||
ipv6: {{ mongodb_net_ipv6_enabled | lower }}
|
||||
maxIncomingConnections: {{ mongodb_net_maxconns }}
|
||||
port: {{ mongodb_net_port }}
|
||||
|
||||
|
||||
security:
|
||||
authorization: {{ 'enabled' if mongodb_rbac_enabled else 'disabled' }}
|
||||
|
||||
#operationProfiling:
|
||||
|
||||
#replication:
|
||||
|
||||
#sharding:
|
||||
|
Loading…
Reference in New Issue
Block a user