Skip to content
Snippets Groups Projects
Commit 7140a7cf authored by nimrod's avatar nimrod
Browse files

Dump of previous work.

parent 217622fc
No related branches found
No related tags found
No related merge requests found
Example mongod 2.6
####### ##########
An (empty) example Ansible role complete with working tests out of the box. For Provision mongod 2.6 on Ubuntu Trusty.
more information read the `blog post
<https://www.shore.co.il/blog/ansible-example-role/>`_.
Requirements Requirements
------------ ------------
...@@ -53,3 +51,14 @@ Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website ...@@ -53,3 +51,14 @@ Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website
<https://www.shore.co.il/>`_. Patches are welcome via `git send-email <https://www.shore.co.il/>`_. Patches are welcome via `git send-email
<http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located <http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located
at: https://www.shore.co.il/git/. at: https://www.shore.co.il/git/.
TODO
----
- Tests.
- Finish replica set work.
- Mail alias.
- Log to syslog.
- Better indication if in replica set, or if rs.initiate finished.
- Don't set fact for auth.
- Handle admin password change.
--- ---
# defaults file for ansible-role-example # defaults file for ansible-role-mongod2.6
mongod_mail_alias: root
mongod_admin_password:
mongod_replset_members: []
mongod_config:
auth: '{{ mongod_admin_password is defined }}'
bind_ip: '0.0.0.0'
keyFile: '{{ mongod_keyFile|default(omit) }}'
replSet: '{{ mongod_replSet|default(omit) }}'
--- ---
# handlers file for ansible-role-example # handlers file for ansible-role-mongod2.6
- name: Restart mongod
service:
name: mongod
state: restarted
galaxy_info: galaxy_info:
author: Nimrod Adar author: Nimrod Adar
description: An example Ansible role description: Provision mongod 2.6 on Ubuntu Trusty
company: Shore technologies company: Shore technologies
license: MIT license: MIT
min_ansible_version: 2.0 min_ansible_version: 2.0
platforms: platforms:
- name: OpenBSD - name: Ubuntu
versions: versions:
- 5.9 - trusty
galaxy_tags: [ ansible ] galaxy_tags: [ mongodb ]
dependencies: dependencies: []
- src: https://www.shore.co.il/git/ansible-role-openbsd-bootstrap
scm: git
name: bootstrap
...@@ -13,10 +13,10 @@ vagrant: ...@@ -13,10 +13,10 @@ vagrant:
- name: virtualbox - name: virtualbox
type: virtualbox type: virtualbox
platforms: platforms:
- name: openbsd - name: ubuntu
box: kaorimatz/openbsd-5.9-amd64 box: ubuntu/trusty64
instances: instances:
- name: ansible-role-example - name: ansible-role-mongod2.6
options: options:
append_platform_to_hostname: yes append_platform_to_hostname: yes
raw_config_args: raw_config_args:
......
--- ---
# tasks file for ansible-role-example # tasks file for ansible-role-mongod2.6
- assert: - assert:
that: that:
- ansible_os_family == 'OpenBSD' - ansible_os_family == 'Debian'
- ansible_distribution_release == '5.9' - ansible_distribution_release == 'trusty'
- mongod_config is defined
- name: Add APT repository key
apt_key:
keyserver: hkp://keyserver.ubuntu.com:80
id: 7F0CEB10
- name: Add APT repository
apt_repository:
repo: deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
state: present
update_cache: yes
- name: APT install
with_items:
- mongodb-org-server
- mongodb-org-shell
- mongodb-org-tools
- python-pymongo
apt:
name: '{{ item }}'
state: present
update_cache: yes
cache_valid_time: 3600
- name: Enable service
service:
name: mongod
enabled: yes
- name: Set mail alias
when: mongod_mail_alias is defined
lineinfile:
dest: /etc/aliases
regexp: mongodb
create: yes
line: 'mongod: {{ mongod_mail_alias }}'
- name: Create dbpath
when: mongod_config.dbpath is defined
file:
dest: '{{ mongod_config.dbpath }}'
owner: mongodb
group: mongodb
state: directory
mode: 0o0750
- name: Create key file
when: mongod_keyFile is defined
template:
dest: /etc/mongod.key
src: mongod.key
owner: mongodb
group: mongodb
mode: 0o0400
- name: Configure
with_dict: '{{ mongod_config }}'
ini_file:
dest: /etc/mongod.conf
option: '{{ item.key }}'
value: '{{ item.value }}'
state: present
notify:
- Restart mongod
- meta: flush_handlers
- name: Wait for service to start
wait_for:
port: 27017
- name: Login without authentication (will fail if accounts were created)
command: mongo admin --eval 'help'
ignore_errors: True
changed_when: False
register: mongod_login_noauth
- name: Set fact if authentication is required
set_fact:
mongod_auth: '{{ mongod_login_noauth|failed }}'
- name: Check if part of replica set
- name: Find replica set primary
- name: Initialize replica set
- name: Add members
- name: Add admin account
{{ mongod_keyFile }}
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
- hosts: all - hosts: all
gather_facts: false gather_facts: false
roles: roles:
- role: ansible-role-example - role: ansible-role-mongod2.6
--- ---
# vars file for ansible-role-example # vars file for ansible-role-mongod2.6
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment