--- - name: Change Crushmap replication from OSD to HOST hosts: ceph_master become: true gather_facts: true vars: ansible_become_password: "{{ ansible_ssh_pass }}" tasks: - name: Create and Run crushmap modification script block: - name: Create crushmap modification script copy: content: | #!/bin/bash ceph osd getcrushmap -o crushmap.cm && crushtool --decompile crushmap.cm -o crushmap.txt && sed -i 's/step chooseleaf firstn 0 type osd/step chooseleaf firstn 0 type host/g' crushmap.txt && crushtool --compile crushmap.txt -o new_crushmap.cm && ceph osd setcrushmap -i new_crushmap.cm && sleep 5 dest: "/root/crushmap.sh" mode: '0755' - name: Run crushmap modification script command: "/root/crushmap.sh" - name: Delete crushmap related files file: path: "/root/{{ item }}" state: absent loop: - crushmap.cm - crushmap.sh - crushmap.txt - new_crushmap.cm - name: Create User and Hostname on ceph-member hosts: ceph_member become: true gather_facts: true vars: ansible_become_password: "{{ ansible_ssh_pass }}" tasks: - name: Ensure ceph packages are installed package: name: "{{ item }}" state: "latest" loop: - sshpass - podman - ceph-common - name: Check if cephadmin user exists command: getent passwd cephadmin register: cephadmin_user ignore_errors: true - name: Create cephadmin user if not exists command: useradd cephadmin when: cephadmin_user.rc != 0 failed_when: false - name: Set password for cephadmin user user: name: cephadmin password: "{{ ansible_ssh_pass | password_hash('sha512') }}" become: true - name: Add cephadmin to sudo group user: name: cephadmin state: present groups: sudo append: yes when: cephadmin_user.rc != 0 - name: Create sudoers file for cephadmin copy: content: "cephadmin ALL=(ALL) NOPASSWD:ALL" dest: "/etc/sudoers.d/cephadmin" mode: '0440' - name: Get cleaned MAC address set_fact: cleaned_mac: "{{ ansible_default_ipv4['macaddress'] | regex_replace('[^a-zA-Z0-9]', '') }}" - name: Generate random hostname based on cleaned MAC address set_fact: random_hostname: "ceph-member-{{ cleaned_mac[-6:] }}" - name: Change hostname hostname: name: "{{ random_hostname }}" - name: Config Upload Directory command: sudo mkdir -p "/home/{{ ansible_user }}/upload/" become: true - name: Permissions Upload Directory command: sudo chown "{{ ansible_user }}":"{{ ansible_user }}" "/home/{{ ansible_user }}/upload/" become: true - name: Send Config from ceph-master to ceph-member hosts: ceph_master become: true gather_facts: true vars: ansible_become_password: "{{ ansible_ssh_pass }}" tasks: - name: Add entry to /etc/hosts lineinfile: path: /etc/hosts line: "{{ hostvars[item]['ansible_default_ipv4']['address'] }} {{ hostvars[item]['ansible_hostname'] }}" state: present loop: "{{ groups['ceph-member'] }}" - name: Install sshpass become: true package: name: sshpass state: latest - name: Copy /etc/hosts to ceph-member servers command: sshpass -p "{{ ansible_ssh_pass }}" scp -o StrictHostKeyChecking=no /etc/hosts {{ ansible_user }}@{{ item }}:~/upload/hosts with_items: "{{ groups['ceph-member'] }}" - name: Copy /etc/ceph to ceph-member servers command: sshpass -p "{{ ansible_ssh_pass }}" scp -r -o StrictHostKeyChecking=no /etc/ceph {{ ansible_user }}@{{ item }}:~/upload/ with_items: "{{ groups['ceph-member'] }}" - name: Copy /home/cephadmin/.ssh/ to ceph-member servers command: sshpass -p "{{ ansible_ssh_pass }}" scp -r -o StrictHostKeyChecking=no /home/cephadmin/.ssh {{ ansible_user }}@{{ item }}:~/upload/ with_items: "{{ groups['ceph-member'] }}" - name: Manage Configs on ceph-member hosts: ceph_member become: true gather_facts: true vars: ansible_become_password: "{{ ansible_ssh_pass }}" tasks: - name: Move hosts file to /etc/hosts command: sudo mv /home/{{ ansible_user }}/upload/hosts /etc/hosts - name: Set ownership for /etc/hosts command: sudo chown root:root /etc/hosts become: true - name: Set permissions for /etc/hosts command: sudo chmod 644 /etc/hosts become: true - name: Remove old Directory /home/cephadmin/.ssh command: sudo rm -rf /home/cephadmin/.ssh become: true - name: Copy SSH Files to cephadmin command: sudo mv /home/{{ ansible_user }}/upload/.ssh /home/cephadmin/ become: true - name: Set permissions for /home/cephadmin/.ssh command: sudo chmod -R 0700 /home/cephadmin/.ssh become: true - name: Permission SSH Directory for cephadmin command: sudo chown -R cephadmin:cephadmin /home/cephadmin/.ssh become: true - name: Delete /etc/ceph command: sudo rm -rf /etc/ceph/ - name: Move Ceph files to /etc/ceph command: sudo mv /home/{{ ansible_user }}/upload/ceph /etc/ceph/ - name: Set ownership for /etc/hosts command: sudo chown root:root /etc/ceph become: true - name: Add ceph-member hosts to Ceph cluster hosts: ceph_master become: true gather_facts: true vars: ansible_become_password: "{{ ansible_ssh_pass }}" tasks: - name: Get ceph-member hostnames from /etc/hosts shell: "grep 'ceph-member' /etc/hosts | awk '{print $2, $1}'" register: ceph_member_hosts_output become: true - name: Add ceph-member hosts to Ceph cluster command: "ceph orch host add {{ item.split(' ')[0] }} {{ item.split(' ')[1] }}" loop: "{{ ceph_member_hosts_output.stdout_lines }}" become: true