rewrite ansible tasks using YAML parameters

parent 2d198bbe
--- ---
- name: restart mongo - name: restart mongo
service: name=mongod state=restarted service:
name: mongod
state: restarted
--- ---
- name: check to see that MongoDB 2.4 is not installed - name: Check to see that MongoDB 2.4 is not installed
stat: path=/etc/init.d/mongodb stat:
path: /etc/init.d/mongodb
register: mongodb_needs_upgrade register: mongodb_needs_upgrade
tags: tags:
- install - install
- install:base - install:base
- name: verify 2.4 not installed - name: Verify 2.4 not installed
fail: msg="MongoDB 2.4 is currently installed and cannot be safely upgraded in a clustered configuration. Please read http://docs.mongodb.org/manual/release-notes/2.6-upgrade/#upgrade-considerations and upgrade to 2.6." fail:
msg: "MongoDB 2.4 is currently installed and cannot be safely upgraded in a clustered configuration. Please read http://docs.mongodb.org/manual/release-notes/2.6-upgrade/#upgrade-considerations and upgrade to 2.6."
when: mongodb_needs_upgrade.stat.exists and MONGO_CLUSTERED when: mongodb_needs_upgrade.stat.exists and MONGO_CLUSTERED
tags: tags:
- install - install
- install:base - install:base
- name: remove mongo 2.4 if present - name: Remove mongo 2.4 if present
apt: > apt:
pkg=mongodb-10gen pkg: mongodb-10gen
state=absent purge=yes state: absent
force=yes purge: yes
force: yes
when: mongodb_needs_upgrade.stat.exists and not MONGO_CLUSTERED when: mongodb_needs_upgrade.stat.exists and not MONGO_CLUSTERED
tags: tags:
- install - install
- install:base - install:base
- name: install python pymongo for mongo_user ansible module - name: Install python pymongo for mongo_user ansible module
pip: > pip:
name=pymongo state=present name: pymongo
version={{ pymongo_version }} extra_args="-i {{ COMMON_PYPI_MIRROR_URL }}" state: present
version: "{{ pymongo_version }}"
extra_args: "-i {{ COMMON_PYPI_MIRROR_URL }}"
tags: tags:
- install - install
- install:base - install:base
- name: add the mongodb signing key - name: Add the mongodb signing key
apt_key: > apt_key:
id={{ MONGODB_APT_KEY }} id: "{{ MONGODB_APT_KEY }}"
keyserver={{ MONGODB_APT_KEYSERVER }} keyserver: "{{ MONGODB_APT_KEYSERVER }}"
state=present state: present
tags: tags:
- install - install
- install:base - install:base
- name: add the mongodb repo to the sources list - name: Add the mongodb repo to the sources list
apt_repository: > apt_repository:
repo='{{ MONGODB_REPO }}' repo: "{{ MONGODB_REPO }}"
state=present state: present
tags: tags:
- install - install
- install:base - install:base
- name: install mongo server and recommends - name: Install mongo server and recommends
apt: > apt:
pkg=mongodb-org={{ mongo_version }} name: "mongodb-org={{ mongo_version }}"
state=present install_recommends=yes state: present
force=yes update_cache=yes install_recommends: yes
force: yes
update_cache: yes
tags: tags:
- install - install
- install:base - install:base
- name: create mongo dirs - name: Create mongo dirs
file: > file:
path="{{ item }}" state=directory path: "{{ item }}"
owner="{{ mongo_user }}" state: directory
group="{{ mongo_user }}" owner: "{{ mongo_user }}"
group: "{{ mongo_user }}"
with_items: with_items:
- "{{ mongo_data_dir }}" - "{{ mongo_data_dir }}"
- "{{ mongo_dbpath }}" - "{{ mongo_dbpath }}"
...@@ -71,83 +79,97 @@ ...@@ -71,83 +79,97 @@
- install - install
- install:base - install:base
- name: stop mongod service - name: Stop mongod service
service: name=mongod state=stopped service:
name: mongod
state: stopped
tags: tags:
- manage - manage
- manage:stop - manage:stop
- name: move mongodb to {{ mongo_data_dir }} - name: Move mongodb to {{ mongo_data_dir }}
command: > command: "mv /var/lib/mongodb {{ mongo_data_dir}}/."
mv /var/lib/mongodb {{ mongo_data_dir}}/. args:
creates={{ mongo_data_dir }}/mongodb creates: "{{ mongo_data_dir }}/mongodb"
tags: tags:
- install - install
- install:base - install:base
- name: copy mongodb key file - name: Copy mongodb key file
copy: > copy:
content="{{ MONGO_CLUSTER_KEY }}" content: "{{ MONGO_CLUSTER_KEY }}"
dest={{ mongo_key_file }} dest: "{{ mongo_key_file }}"
mode=0600 mode: "0600"
owner=mongodb owner: mongodb
group=mongodb group: mongodb
when: MONGO_CLUSTERED when: MONGO_CLUSTERED
tags: tags:
- install - install
- install:configuration - install:configuration
- name: copy configuration template - name: Copy configuration template
template: src=mongodb.conf.j2 dest=/etc/mongod.conf backup=yes template:
notify: restart mongo src: "mongodb.conf.j2"
dest: "/etc/mongod.conf"
backup: yes
notify:
- restart mongo
tags: tags:
- install - install
- install:configuration - install:configuration
- name: start mongo service - name: Start mongo service
service: name=mongod state=started service:
name: mongod
state: started
tags: tags:
- manage - manage
- manage:start - manage:start
- name: wait for mongo server to start - name: Wait for mongo server to start
wait_for: port=27017 delay=2 wait_for:
port: 27017
delay: 2
tags: tags:
- manage - manage
- manage:start - manage:start
- name: drop super user script - name: Drop super user script
template: src="create_root.js.j2" dest="/tmp/create_root.js" template:
src: "create_root.js.j2"
dest: "/tmp/create_root.js"
when: not MONGO_CLUSTERED when: not MONGO_CLUSTERED
tags: tags:
- install - install
- install:configuration - install:configuration
- name: create super user with js - name: Create super user with js
shell: > shell: "/usr/bin/mongo admin /tmp/create_root.js"
/usr/bin/mongo admin /tmp/create_root.js
when: not MONGO_CLUSTERED when: not MONGO_CLUSTERED
tags: tags:
- install - install
- install:configuration - install:configuration
- name: delete super user script - name: Delete super user script
file: path=/tmp/create_root.js state=absent file:
path: /tmp/create_root.js
state: absent
when: not MONGO_CLUSTERED when: not MONGO_CLUSTERED
tags: tags:
- install - install
- install:configuration - install:configuration
- name: Create the file to initialize the mongod replica set - name: Create the file to initialize the mongod replica set
template: src=repset_init.js.j2 dest=/tmp/repset_init.js template:
src: "repset_init.js.j2"
dest: "/tmp/repset_init.js"
when: MONGO_CLUSTERED when: MONGO_CLUSTERED
tags: tags:
- install - install
- install:configuration - install:configuration
- name: Initialize the replication set - name: Initialize the replication set
shell: > shell: "/usr/bin/mongo /tmp/repset_init.js"
/usr/bin/mongo /tmp/repset_init.js
when: MONGO_CLUSTERED when: MONGO_CLUSTERED
tags: tags:
- install - install
...@@ -157,81 +179,72 @@ ...@@ -157,81 +179,72 @@
# file: path=/tmp/repset_init.js state=absent # file: path=/tmp/repset_init.js state=absent
# when: MONGO_CLUSTERED # when: MONGO_CLUSTERED
- name: create a mongodb user - name: Create a mongodb user
mongodb_user: > mongodb_user:
database={{ item.database }} database: "{{ item.database }}"
login_user={{ MONGO_ADMIN_USER }} login_user: "{{ MONGO_ADMIN_USER }}"
login_password={{ MONGO_ADMIN_PASSWORD }} login_password: "{{ MONGO_ADMIN_PASSWORD }}"
name={{ item.user }} name: "{{ item.user }}"
password="{{ item.password }}" password: "{{ item.password }}"
roles={{ item.roles }} roles: "{{ item.roles }}"
state=present state: present
with_items: MONGO_USERS with_items: "{{ MONGO_USERS }}"
when: not MONGO_CLUSTERED when: not MONGO_CLUSTERED
tags: tags:
- manage - manage
- manage:app-users - manage:app-users
- name: create a mongodb user - name: Create a mongodb user
mongodb_user: > mongodb_user:
database={{ item.database }} database: "{{ item.database }}"
login_user={{ MONGO_ADMIN_USER }} login_user: "{{ MONGO_ADMIN_USER }}"
login_password={{ MONGO_ADMIN_PASSWORD }} login_password: "{{ MONGO_ADMIN_PASSWORD }}"
name={{ item.user }} name: "{{ item.user }}"
password="{{ item.password }}" password: "{{ item.password }}"
roles={{ item.roles }} roles: "{{ item.roles }}"
state=present state: present
replica_set={{ mongo_repl_set }} replica_set: "{{ mongo_repl_set }}"
with_items: MONGO_USERS with_items: "{{ MONGO_USERS }}"
when: MONGO_CLUSTERED when: MONGO_CLUSTERED
tags: tags:
- manage - manage
- manage:app-users - manage:app-users
- name: install s3cmd - name: Install s3cmd
pip: > pip:
name="s3cmd" name: "s3cmd"
state=present state: present
extra_args="-i {{ COMMON_PYPI_MIRROR_URL }}" extra_args: "-i {{ COMMON_PYPI_MIRROR_URL }}"
when: MONGO_S3_BACKUP when: MONGO_S3_BACKUP
tags: tags:
- install - install
- install:app-requirements - install:app-requirements
- name: configure s3cmd - name: Configure s3cmd and install backup-mongo-to-s3 script
template: > template:
dest="{{ MONGO_S3_S3CMD_CONFIG }}" dest: "{{ item.dest }}"
src=mongo-s3-backup-s3cfg.j2 src: "{{ item.src }}"
owner=root owner: root
group=root group: root
mode=0600 mode: "{{ item.mode }}"
when: MONGO_S3_BACKUP
tags:
- install
- install:configuration
- name: install backup-mongo-to-s3 script
template: >
src=backup-mongo-to-s3.j2
dest=/edx/bin/backup-mongo-to-s3.sh
owner=root
group=root
mode=0700
when: MONGO_S3_BACKUP when: MONGO_S3_BACKUP
with_items:
- { src: 'mongo-s3-backup-s3cfg.j2', dest: '{{ MONGO_S3_S3CMD_CONFIG }}', mode: '0600' }
- { src: 'backup-mongo-to-s3.j2', dest: '/edx/bin/backup-mongo-to-s3.sh', mode: '0700' }
tags: tags:
- install - install
- install:configuration - install:configuration
- name: schedule backup-mongo-to-3s crontab - name: Schedule backup-mongo-to-3s crontab
cron: cron:
name="backup-mongo-to-s3" name: "backup-mongo-to-s3"
job="/edx/bin/backup-mongo-to-s3.sh" job: "/edx/bin/backup-mongo-to-s3.sh"
backup=yes backup: yes
cron_file=backup-mongo-to-s3 cron_file: backup-mongo-to-s3
user=root user: root
hour="{{ MONGO_S3_BACKUP_HOUR }}" hour: "{{ MONGO_S3_BACKUP_HOUR }}"
minute="0" minute: "0"
day="{{ MONGO_S3_BACKUP_DAY }}" day: "{{ MONGO_S3_BACKUP_DAY }}"
when: MONGO_S3_BACKUP when: MONGO_S3_BACKUP
tags: tags:
- install - install
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment