diff --git a/README.rst b/README.rst index 06fb1d664e0ac8ddbe0ea61703cdc273cea719e6..240c5b4970bc927fbcf84a590f0051105be83aed 100644 --- a/README.rst +++ b/README.rst @@ -1,9 +1,7 @@ -Example -####### +mongod 2.6 +########## -An (empty) example Ansible role complete with working tests out of the box. For -more information read the `blog post -<https://www.shore.co.il/blog/ansible-example-role/>`_. +Provision mongod 2.6 on Ubuntu Trusty. Requirements ------------ @@ -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 <http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located 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. diff --git a/defaults/main.yml b/defaults/main.yml index 25ca86f325b131ae189e74bc108bcc2bc403501e..4a84e7df9044ee9d8d9eba60c5104f166d419260 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,10 @@ --- -# 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) }}' diff --git a/handlers/main.yml b/handlers/main.yml index 1d74a03c15eb4a405872128a9f81f91ecf354f2e..ff555d5eff549b5b7190fbe4ed16b1b74faf867c 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,6 @@ --- -# handlers file for ansible-role-example +# handlers file for ansible-role-mongod2.6 +- name: Restart mongod + service: + name: mongod + state: restarted diff --git a/meta/main.yml b/meta/main.yml index e22f4e836a3c46a95e906533a0fd5976a885775c..9729c1171f1110ee321166dd2ad761ee604ee762 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,15 +1,12 @@ galaxy_info: author: Nimrod Adar - description: An example Ansible role + description: Provision mongod 2.6 on Ubuntu Trusty company: Shore technologies license: MIT min_ansible_version: 2.0 platforms: - - name: OpenBSD + - name: Ubuntu versions: - - 5.9 - galaxy_tags: [ ansible ] -dependencies: - - src: https://www.shore.co.il/git/ansible-role-openbsd-bootstrap - scm: git - name: bootstrap + - trusty + galaxy_tags: [ mongodb ] +dependencies: [] diff --git a/molecule.yml b/molecule.yml index 0d86e79f8d760dd0d6acf0a8d89cea909dec37a5..2c35840ca476bc0c24f732616b0ed7fd7f21e5f4 100644 --- a/molecule.yml +++ b/molecule.yml @@ -13,10 +13,10 @@ vagrant: - name: virtualbox type: virtualbox platforms: - - name: openbsd - box: kaorimatz/openbsd-5.9-amd64 + - name: ubuntu + box: ubuntu/trusty64 instances: - - name: ansible-role-example + - name: ansible-role-mongod2.6 options: append_platform_to_hostname: yes raw_config_args: diff --git a/tasks/main.yml b/tasks/main.yml index 066751cb957b869527eef43b28af7dbd81ba96d2..a2a732d5d267d10383b826a107e58c2e618318f0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,7 +1,98 @@ --- -# tasks file for ansible-role-example +# tasks file for ansible-role-mongod2.6 - assert: that: - - ansible_os_family == 'OpenBSD' - - ansible_distribution_release == '5.9' + - ansible_os_family == 'Debian' + - 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 diff --git a/templates/mongod.key b/templates/mongod.key new file mode 100644 index 0000000000000000000000000000000000000000..d3b229613c15bb8ad2c83577acbcf71a103dfc96 --- /dev/null +++ b/templates/mongod.key @@ -0,0 +1 @@ +{{ mongod_keyFile }} diff --git a/tests/playbook.yml b/tests/playbook.yml index e739a2b8827a164702a059f09277dd60fa516e36..4f19e1b9902b1d4ef3b0322df24d64269c1561ff 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -2,4 +2,4 @@ - hosts: all gather_facts: false roles: - - role: ansible-role-example + - role: ansible-role-mongod2.6 diff --git a/vars/main.yml b/vars/main.yml index 241750308ae0dc5fd6fc0d21108c47746696d808..0b6672378510f7870278e58f99374cc1a8fdcfad 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ --- -# vars file for ansible-role-example +# vars file for ansible-role-mongod2.6