diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..94951b6 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,8 @@ +[defaults] +#roles_path = ./redis_role +inventory = /home/sahil/minio_ansible/minio_role/aws_ec2.yml +host_key_checking = False +remote_user = ubuntu +private_key_file = /home/sahil/Downloads/minio.pem +#[inventory] +#enable_plugins = aws_ec2 diff --git a/aws_ec2.yml b/aws_ec2.yml new file mode 100644 index 0000000..24f12a8 --- /dev/null +++ b/aws_ec2.yml @@ -0,0 +1,11 @@ +--- +plugin: aws_ec2 +regions: + - ap-northeast-2 + +filters: + tag:Name: minio + +ansible_user: "ubuntu" +host_key_checking: False +ansible_ssh_private_key_file: /home/sahil/downloads/minio.pem diff --git a/minio_role/README.md b/minio_role/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/minio_role/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/minio_role/defaults/main.yml b/minio_role/defaults/main.yml new file mode 100644 index 0000000..72b6add --- /dev/null +++ b/minio_role/defaults/main.yml @@ -0,0 +1,10 @@ +--- +# defaults file for minio_role +minio_version: "RELEASE.2024-08-01T00-00-00Z" +minio_port: 9000 +minio_data_dir: /data/minio +minio_config_dir: /etc/minio +minio_user: minio +minio_group: minio +minio_access_key: "minio1234567890" +minio_secret_key: "1234567890minio" diff --git a/minio_role/files/minio.service b/minio_role/files/minio.service new file mode 100644 index 0000000..9c84288 --- /dev/null +++ b/minio_role/files/minio.service @@ -0,0 +1,14 @@ +[Unit] +Description=MinIO +Documentation=https://docs.min.io +After=network.target + +[Service] +User=minio +Group=minio +ExecStart=/usr/local/bin/minio server /data --config-dir /etc/minio +Restart=on-failure +EnvironmentFile=-/etc/default/minio + +[Install] +WantedBy=multi-user.target diff --git a/minio_role/handlers/main.yml b/minio_role/handlers/main.yml new file mode 100644 index 0000000..b0e1af4 --- /dev/null +++ b/minio_role/handlers/main.yml @@ -0,0 +1,19 @@ +--- +# handlers file for minio_role + +- name: Restart MinIO + systemd: + name: "{{ handlers.restart_minio.name }}" + state: "{{ handlers.restart_minio.state }}" + +- name: Reload systemd + command: "{{ handlers.reload_systemd.command }}" + become: "{{ handlers.reload_systemd.become }}" + async: "{{ handlers.reload_systemd.async }}" + poll: "{{ handlers.reload_systemd.poll }}" + register: result + +- name: Debug systemd reload result + debug: + var: "{{ handlers.debug_systemd_result.debug_var }}" + become: "{{ handlers.debug_systemd_result.become }}" diff --git a/minio_role/meta/main.yml b/minio_role/meta/main.yml new file mode 100644 index 0000000..e2e9c70 --- /dev/null +++ b/minio_role/meta/main.yml @@ -0,0 +1,10 @@ +--- +# meta file for minio_role + +dependencies: [] + +galaxy_info: + author: "{{ author }}" + description: "{{ description }}" + company: "{{ company }}" + license: "{{ license }}" diff --git a/minio_role/tasks/configure.yml b/minio_role/tasks/configure.yml new file mode 100644 index 0000000..4c13e10 --- /dev/null +++ b/minio_role/tasks/configure.yml @@ -0,0 +1,91 @@ +--- +- name: Ensure minio group exists + group: + name: "{{ minio_group_name }}" + state: present + retries: 5 + delay: 5 + until: result is success + register: result + become: yes + +- name: Ensure minio user exists + user: + name: "{{ minio_user_name }}" + group: "{{ minio_group_name }}" + create_home: yes + shell: "{{ minio_user_shell }}" + state: present + become: yes + +- name: Create MinIO configuration directory + file: + path: "{{ minio_config_dir }}" + state: directory + mode: "{{ directory_mode }}" + owner: "{{ minio_user_name }}" + group: "{{ minio_group_name }}" + become: yes + +- name: Create MinIO group + group: + name: "{{ minio_group_name }}" + state: present + become: yes + when: ansible_os_family in ['RedHat', 'Debian', 'CentOS'] + + +- name: Create MinIO user + user: + name: "{{ minio_user_name }}" + group: "{{ minio_group_name }}" + system: "{{ minio_user_system }}" + shell: "{{ minio_user_shell }}" + become: yes + +- name: Set ownership of MinIO binary + file: + path: "{{ minio_binary_path }}" + owner: "{{ minio_user_name }}" + group: "{{ minio_group_name }}" + mode: "{{ directory_mode }}" + become: yes + +- name: Set ownership of MinIO data directory + file: + path: "{{ minio_data_dir }}" + owner: "{{ minio_user_name }}" + group: "{{ minio_group_name }}" + recurse: yes + become: yes + +- name: Set ownership of MinIO config directory + file: + path: "{{ minio_config_dir }}" + owner: "{{ minio_user_name }}" + group: "{{ minio_group_name }}" + recurse: yes + become: yes + +- name: Copy MinIO service file + copy: + src: "{{ minio_service_src }}" + dest: "{{ minio_service_dest }}" + mode: "{{ file_mode }}" + become: yes + +- name: Ensure MinIO data directories exist + file: + path: "{{ item }}" + state: directory + owner: minio + group: minio + mode: '0755' + loop: "{{ minio_data_dirs[deployment_type] }}" + when: deployment_type in ['single-node-single-drive', 'single-node-multi-drive', 'multi-node-multi-drive'] + + +- name: Start MinIO server with the chosen deployment type + include_tasks: "{{ deployment_type }}.yml" + when: deployment_type in ['single-node-single-drive', 'single-node-multi-drive', 'multi-node-multi-drive'] + \ No newline at end of file diff --git a/minio_role/tasks/install.yml b/minio_role/tasks/install.yml new file mode 100644 index 0000000..776a6d7 --- /dev/null +++ b/minio_role/tasks/install.yml @@ -0,0 +1,85 @@ +--- + +- name: Install required packages on RedHat-based systems + yum: + name: + - wget + - unzip + state: present + when: ansible_os_family == "RedHat" + +- name: Install required packages on Debian-based systems + apt: + name: + - wget + - unzip + state: present + update_cache: yes + when: ansible_os_family == "Debian" + become: yes + +- name: Install required packages on CentOS + yum: + name: + - wget + - unzip + state: present + when: ansible_distribution == "CentOS" + become: yes + +- name: Download MinIO binary + get_url: + url: "https://dl.min.io/server/minio/release/linux-amd64/minio" + dest: "/usr/local/bin/minio" + mode: '0755' + +- name: Create MinIO service file on RedHat-based systems + template: + src: "minio.service.j2" + dest: "/etc/systemd/system/minio.service" + when: ansible_os_family == "RedHat" + +- name: Create MinIO service file on Debian-based systems + template: + src: "minio.service.j2" + dest: "/etc/systemd/system/minio.service" + when: ansible_os_family == "Debian" + +- name: Create MinIO service file on CentOS + template: + src: "minio.service.j2" + dest: "/etc/systemd/system/minio.service" + when: ansible_distribution == "CentOS" + +- name: Update apt package list + ansible.builtin.apt: + update_cache: "{{ update_cache }}" + become: yes + +- name: Download MinIO binary + get_url: + url: "{{ minio_download_url }}" + dest: "{{ minio_deb_path }}" + mode: "{{ deb_file_mode }}" + become: yes + +- name: Install MinIO binary + apt: + deb: "{{ minio_deb_path }}" + become: yes + +- name: Ensure MinIO binary has execute permissions + file: + path: "{{ minio_deb_path }}" + mode: '0755' + owner: minio + group: minio + become: yes + + + + + + + + diff --git a/minio_role/tasks/main.yml b/minio_role/tasks/main.yml new file mode 100644 index 0000000..84ef559 --- /dev/null +++ b/minio_role/tasks/main.yml @@ -0,0 +1,8 @@ +--- +- name: Install MinIO + include_tasks: "install.yml" + +- name: Configure MinIO + include_tasks: "configure.yml" + + diff --git a/minio_role/tasks/multi-node-multi-drive.yml b/minio_role/tasks/multi-node-multi-drive.yml new file mode 100644 index 0000000..60aaba0 --- /dev/null +++ b/minio_role/tasks/multi-node-multi-drive.yml @@ -0,0 +1,8 @@ +--- +- name: Start MinIO server with multiple drives + command: "minio server {{ minio_data_dirs[deployment_type]|join(' ') }} --config-dir /etc/minio" + environment: + MINIO_ACCESS_KEY: "{{ minio_access_key }}" + MINIO_SECRET_KEY: "{{ minio_secret_key }}" + become: yes + become_user: minio_user diff --git a/minio_role/tasks/single-node-multi-drive.yml b/minio_role/tasks/single-node-multi-drive.yml new file mode 100644 index 0000000..97b275a --- /dev/null +++ b/minio_role/tasks/single-node-multi-drive.yml @@ -0,0 +1,10 @@ +--- +- name: Start MinIO server with multiple drives + command: "minio server /data/minio1 /data/minio2 /data/minio3 /data/minio4 --config-dir /etc/minio" + environment: + MINIO_ACCESS_KEY: "{{ minio_access_key }}" + MINIO_SECRET_KEY: "{{ minio_secret_key }}" + state: started + enabled: yes + become: yes + diff --git a/minio_role/tasks/single-node-single-drive.yml b/minio_role/tasks/single-node-single-drive.yml new file mode 100644 index 0000000..863c509 --- /dev/null +++ b/minio_role/tasks/single-node-single-drive.yml @@ -0,0 +1,8 @@ +--- +- name: Start MinIO server with single drive + command: "minio server /data/minio1 " + environment: + MINIO_ACCESS_KEY: "{{ minio_access_key }}" + MINIO_SECRET_KEY: "{{ minio_secret_key }}" + become: yes + diff --git a/minio_role/templates/minio.conf.j2 b/minio_role/templates/minio.conf.j2 new file mode 100644 index 0000000..43dc303 --- /dev/null +++ b/minio_role/templates/minio.conf.j2 @@ -0,0 +1,3 @@ +# minio.conf.j2 +MINIO_ACCESS_KEY={{ minio_access_key }} +MINIO_SECRET_KEY={{ minio_secret_key }} diff --git a/minio_role/vars/main.yml b/minio_role/vars/main.yml new file mode 100644 index 0000000..c4b0d42 --- /dev/null +++ b/minio_role/vars/main.yml @@ -0,0 +1,108 @@ +--- +# handlers variables + +handlers.restart_minio.name: minio +handlers.restart_minio.state: restarted +handlers.reload_systemd.command: systemctl daemon-reload +handlers.reload_systemd.become: yes +handlers.reload_systemd.async: 120 +handlers.reload_systemd.poll: 10 +handlers.debug_systemd_result.debug_var: result +handlers.debug_systemd_result.become: yes + + +# Variables for role metadata + +# Galaxy info +author: "your_name" +description: "Ansible role for MinIO" +company: "your_company" +license: "license_name" + +# Variables for configuring MinIO + +# Group and user settings +minio_group_name: "minio" +minio_user_name: "minio" +minio_user_shell: "/sbin/nologin" +minio_user_home: "/home/minio" +minio_user_system: yes + +# MinIO directories and ownership +minio_config_dir: "/etc/minio" +minio_data_dir: "/data" +minio_binary_path: "/usr/local/bin/minio" +minio_service_src: "minio.service" +minio_service_dest: "/etc/systemd/system/minio.service" + +# Permissions +directory_mode: "0755" +file_mode: "0644" + +# Variables for installing MinIO + +# MinIO binary download URL +minio_download_url: "https://dl.min.io/server/minio/release/linux-amd64/archive/minio_20240731054626.0.0_amd64.deb" + +# File paths and permissions +minio_deb_path: "/tmp/minio.deb" +deb_file_mode: "0755" + + +# Variables for Debian-based systems tasks + +# Update apt package list +update_cache: yes + +# File paths for tasks +install_tasks_file: "install.yml" +configure_tasks_file: "configure.yml" + + +# General MinIO configuration +minio_version: "RELEASE.2024-08-01T00-00-00Z" +minio_port: 9000 +minio_access_key: "minio1234567890" +minio_secret_key: "1234567890minio" + +minio_data_dirs: + single-node-single-drive: + - /data/minio1 + single-node-multi-drive: + - /data/minio1 + - /data/minio2 + - /data/minio3 + - /data/minio4 + multi-node-multi-drive: + - /data/minio1 + - /data/minio2 + - /data/minio3 + - /data/minio4 + +# OS specific +minio_user: "minio" +minio_group: "minio" + +minio_packages: + RedHat: + - wget + - unzip + Debian: + - wget + - unzip + CentOS: + - wget + - unzip + +minio_service: + RedHat: "minio" + Debian: "minio" + CentOS: "minio" + + + + + + + + diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..e4130b0 --- /dev/null +++ b/playbook.yml @@ -0,0 +1,9 @@ +--- +- hosts: aws_ec2 + vars_prompt: + - name: "deployment_type" + prompt: "Which type of deployment do you want (single-node-single-drive, single-node-multi-drive, multi-node-multi-drive)?" + private: no + + roles: + - minio_role