Skip to content

Instantly share code, notes, and snippets.

@Puneeth-n
Created February 7, 2021 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Puneeth-n/c632895d220d57c6b8a0b2545b8993f2 to your computer and use it in GitHub Desktop.
Save Puneeth-n/c632895d220d57c6b8a0b2545b8993f2 to your computer and use it in GitHub Desktop.
- hosts: localhost
connection: local
gather_facts: true
become: true
tasks:
- name: Get empty devices
set_fact:
additional_disk_devices: "{{ additional_disk_devices|default([]) }} + [ '/dev/{{ item }}' ]"
when: '"nvme" in item and (ansible_devices[item].partitions | length) == 0'
with_items: "{{ ansible_devices }}"
- name: Formatting the MongoDB data volume
filesystem:
fstype: xfs
dev: "{{ item }}"
when: ( additional_disk_devices | length ) > 0
with_items: "{{ additional_disk_devices }}"
- name: Get UUID for {{ additional_disk_devices }}
command: blkid "{{ item }}" -sUUID -ovalue
when: ( additional_disk_devices | length ) > 0
with_items: "{{ additional_disk_devices }}"
register: blkid
- name: Set list of UUIDs
set_fact:
additional_disk_devices_uuids: "{{ addtional_disk_devices_uuids|default([]) }} + ['{{ item }}']"
with_items: "{{ blkid.results | map(attribute='stdout_lines') | list }}"
- name: Mounting the MongoDB data volume
mount:
path: /data
src: "UUID={{ item }}"
fstype: xfs
opts: noatime,noexec
state: mounted
with_items: "{{ additional_disk_devices_uuids }}"
- name: Ensure group "mongodb" exists
group:
name: mongodb
- name: Add user "mongodb"
user:
name: mongodb
groups: mongodb
shell: /sbin/nologin
append: yes
comment: 'mongodb nologin User'
state: present
- name: Create MongoDB automation agent directory
file:
path: /etc/mongodb-mms
state: directory
- name: Create MongoDB data directory
file:
path: /data
state: directory
recurse: yes
owner: mongodb
group: mongodb
- name: Create MongoDB automation agent configuration
template:
src: automation-agent.config.j2
dest: /etc/mongodb-mms/automation-agent.config
mode: 0600
vars:
mms_api_key: '{{ ansible_env.MMS_API_KEY }}'
mms_group_id: '{{ ansible_env.MMS_GROUP_ID }}'
- name: Install MongoDB automation agent
apt:
deb: 'https://cloud.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager_10.15.1.6468-1_amd64.ubuntu1604.deb'
notify:
- restart mongodb-mms-automation-agent.service
- name: Install the dependencies for Mongo 4.0
package:
name:
- libcurl4
- libgssapi-krb5-2
- libkrb5-dbg
- libldap-2.4-2
- libpci3
- libsasl2-2
- snmp
- liblzma5
- openssl
state: present
- name:
template:
src: ct-register.service.j2
dest: /etc/systemd/system/ct-register.service
mode: 0600
notify:
- enable ct-register.service
handlers:
- name: restart mongodb-mms-automation-agent.service
service:
name: mongodb-mms-automation-agent.service
state: restarted
enabled: yes
- name: enable ct-register.service
service:
name: ct-register.service
enabled: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment