From a3880a46980f07c0c425de8e266fa58584b11eb6 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sat, 12 Jan 2019 14:40:16 +0100 Subject: [PATCH] fix ansible guideine errors --- meta/main.yml | 7 ++-- tasks/auth.yml | 58 +++++++++++++++--------------- tasks/config.yml | 22 ++++++------ tasks/install.yml | 91 ++++++++++++++++++++++++----------------------- tasks/storage.yml | 41 ++++++++++----------- 5 files changed, 112 insertions(+), 107 deletions(-) diff --git a/meta/main.yml b/meta/main.yml index 1b88225..7f36adc 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,3 +1,4 @@ +# Standards: 0.1 --- galaxy_info: author: xoxys @@ -5,9 +6,9 @@ galaxy_info: license: MIT min_ansible_version: 2.4 platforms: - - name: EL - versions: - - 7 + - name: EL + versions: + - 7 galaxy_tags: - db - mongodb diff --git a/tasks/auth.yml b/tasks/auth.yml index decd044..0d170de 100644 --- a/tasks/auth.yml +++ b/tasks/auth.yml @@ -1,25 +1,26 @@ --- - block: - - name: Backup current config file - copy: - src: /etc/mongod.conf - dest: /etc/mongod.conf.bak - remote_src: True - changed_when: False + - name: Backup current config file + copy: + src: /etc/mongod.conf + dest: /etc/mongod.conf.bak + remote_src: True + changed_when: False - - name: Deploy config file without auth - template: - src: etc/mongod_init.conf.j2 - dest: /etc/mongod.conf - mode: 0644 - changed_when: False + - name: Deploy config file without auth + template: + src: etc/mongod_init.conf.j2 + dest: /etc/mongod.conf + mode: 0644 + changed_when: False - - name: Restart service - service: - name: mongod - state: restarted - changed_when: False + - name: Restart service to disable auth + service: + name: mongod + state: restarted + changed_when: False become: True + become_user: root - name: Create admin user mongodb_user: @@ -30,16 +31,17 @@ state: present - block: - - name: Restore config file - copy: - src: /etc/mongod.conf.bak - dest: /etc/mongod.conf - remote_src: True - changed_when: False + - name: Restore config file + copy: + src: /etc/mongod.conf.bak + dest: /etc/mongod.conf + remote_src: True + changed_when: False - - name: Restart service - service: - name: mongod - state: restarted - changed_when: False + - name: Restart service to re-enable auth + service: + name: mongod + state: restarted + changed_when: False become: True + become_user: root diff --git a/tasks/config.yml b/tasks/config.yml index cafd706..4e92bd8 100644 --- a/tasks/config.yml +++ b/tasks/config.yml @@ -1,16 +1,16 @@ --- - block: - - name: Deploy configuration file - template: - src: etc/mongod.conf.j2 - dest: /etc/mongod.conf - mode: 0644 - notify: __mongod_restart + - 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 - service: - name: mongod - state: started - enabled: yes + - name: Make sure mongodb is up and running + service: + name: mongod + state: started + enabled: yes become: True become_user: root diff --git a/tasks/install.yml b/tasks/install.yml index bcdbc82..877df2e 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,56 +1,57 @@ --- - block: - - name: Add repository for major version '{{ mongodb_version }}' - yum_repository: - name: mongodb - description: MongoDB Repository - baseurl: "https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/{{ mongodb_version }}/x86_64/" - gpgcheck: yes - enabled: yes - gpgkey: "https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc" + - name: Add repository for major version '{{ mongodb_version }}' + yum_repository: + name: mongodb + description: MongoDB Repository + baseurl: "https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/{{ mongodb_version }}/x86_64/" + gpgcheck: yes + enabled: yes + gpgkey: "https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc" - - name: Install packages - package: - name: "{{ item }}" - state: present - with_items: - - mongodb-org - - python2-pip + - name: Install packages + package: + name: "{{ item }}" + state: present + with_items: + - mongodb-org + - python2-pip - - name: Create group '{{ mongodb_system_group }}' - group: - name: "{{ mongodb_system_group }}" - gid: "{{ mongodb_system_gid | default(omit) }}" - state: present + - name: Create group '{{ mongodb_system_group }}' + group: + name: "{{ mongodb_system_group }}" + gid: "{{ mongodb_system_gid | default(omit) }}" + state: present - - name: Create user '{{ mongodb_system_user }}' - user: - name: "{{ mongodb_system_user }}" - uid: "{{ mongodb_system_uid | default(omit) }}" - group: "{{ mongodb_system_group }}" + - name: Create user '{{ mongodb_system_user }}' + user: + name: "{{ mongodb_system_user }}" + uid: "{{ mongodb_system_uid | default(omit) }}" + group: "{{ mongodb_system_group }}" - - name: Create db storage dir '{{ mongodb_storage_dbpath }}' - file: - path: "{{ mongodb_storage_dbpath }}" - owner: "{{ mongodb_system_user }}" - group: "{{ mongodb_system_group }}" - selevel: s0 - serole : object_r - setype: mongod_var_lib_t - seuser: system_u - state: directory - notify: __mongod_restart + - name: Create db storage dir '{{ mongodb_storage_dbpath }}' + file: + path: "{{ mongodb_storage_dbpath }}" + owner: "{{ mongodb_system_user }}" + group: "{{ mongodb_system_group }}" + selevel: s0 + serole : object_r + setype: mongod_var_lib_t + seuser: system_u + state: directory + notify: __mongod_restart - - 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' - notify: __mongod_restart + - 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' + notify: __mongod_restart become: True + become_user: root - name: Install pymongo as ansible dependency pip: diff --git a/tasks/storage.yml b/tasks/storage.yml index c8cf22e..f9fd697 100644 --- a/tasks/storage.yml +++ b/tasks/storage.yml @@ -1,26 +1,27 @@ --- - block: - - name: Create volume group '{{ mongodb_lvm_vg }}' - lvg: - vg: "{{ mongodb_lvm_vg }}" - pvs: "{{ mongodb_lvm_pvs|join(',') }}" + - 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 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 }}" - resizefs: True + - 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 }}" + resizefs: True - - 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: 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 become: True + become_user: root