--- - name: Configure swappiness ansible.builtin.copy: src: 99-swappiness.conf dest: /etc/sysctl.d/99-swappiness.conf mode: '0644' owner: root group: root - name: Install mongodb block: - name: Check if mongodb up ansible.builtin.systemd_service: name: mongodb.service state: started check_mode: true rescue: - name: Install mongodb config ansible.builtin.copy: src: mongodb.conf dest: /etc/mongodb.conf mode: '0644' owner: root group: root - name: Start and enable mongodb ansible.builtin.systemd_service: name: mongodb.service state: started enabled: true - name: Setup admin account community.mongodb.mongodb_user: database: admin name: root password: "{{ mongodb_root_password }}" state: present roles: root - name: Apply authorization ansible.builtin.blockinfile: path: /etc/mongodb.conf block: | security: authorization: "enabled" notify: Restart mongodb - name: Flush handlers ansible.builtin.meta: flush_handlers