Skip to content

Commit

Permalink
modules: migrate all modules to ceph.automation collection
Browse files Browse the repository at this point in the history
- move all library/ and modules_utils/ content to collection
- fix ansible-lint problems task names to uppercase and use modules fqcn.
- add ceph.automation collection dependency

Signed-off-by: Teoman ONAY <[email protected]>
  • Loading branch information
asm0deuz committed Jun 21, 2024
1 parent 2bbeb77 commit 8ea6806
Show file tree
Hide file tree
Showing 25 changed files with 261 additions and 2,303 deletions.
2 changes: 0 additions & 2 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[defaults]
log_path = $HOME/ansible/ansible.log
library = ./library
module_utils = ./module_utils
roles_path = ./

forks = 20
Expand Down
76 changes: 38 additions & 38 deletions cephadm-clients.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@
- run_once: true
delegate_to: localhost
block:
- name: import_role ceph_defaults
import_role:
- name: Import_role ceph_defaults
ansible.builtin.import_role:
name: ceph_defaults

- name: fail if the fsid parameter is missing
fail:
- name: Fail if the fsid parameter is missing
ansible.builtin.fail:
msg: >
You must supply an 'fsid' parameter for the corresponding ceph cluster
when: fsid is undefined

- name: fail if admin group doesn't exist or is empty
fail:
- name: Fail if admin group doesn't exist or is empty
ansible.builtin.fail:
msg: |
You must define a group [admin] in your inventory which provides the
keyring that you want to distribute
when: "'admin' not in groups or groups['admin'] | length < 1"

- name: fail if client_group is NOT in the inventory
fail:
- name: Fail if client_group is NOT in the inventory
ansible.builtin.fail:
msg: >
Variable client_group '{{ client_group }}' is not defined in the inventory
when: client_group not in groups

- name: fail if keyring variable is missing
fail:
- name: Fail if keyring variable is missing
ansible.builtin.fail:
msg: |
You must supply a 'keyring' variable that defines the path to the key
that you want to distribute to your client machines
Expand All @@ -69,38 +69,38 @@
gather_facts: false
tasks:

- name: check fsid is present on {{ inventory_hostname }}
stat:
- name: Check fsid is present on {{ inventory_hostname }}
ansible.builtin.stat:
path: /var/lib/ceph/{{ fsid }}
register: fsid_stat

- name: fail if fsid is not present
fail:
- name: Fail if fsid is not present
ansible.builtin.fail:
msg: >
The given fsid ({{ fsid }}), is not present in /var/lib/ceph on {{ inventory_hostname }}
when:
- not fsid_stat.stat.exists | bool
- not fsid_stat.stat.isdir | bool

- name: check keyring status on {{ inventory_hostname }}
stat:
- name: Check keyring status on {{ inventory_hostname }}
ansible.builtin.stat:
path: "{{ keyring }}"
register: keyring_stat

- name: fail if keyring not found on {{ inventory_hostname }}
fail:
- name: Fail if keyring not found on {{ inventory_hostname }}
ansible.builtin.fail:
msg: >
The keyring path provided '{{ keyring }}' can not be found on {{ inventory_hostname }}
when: not keyring_stat.stat.exists | bool

- name: check conf is OK to use
stat:
- name: Check conf is OK to use
ansible.builtin.stat:
path: "{{ conf }}"
register: conf_stat
when: conf is defined

- name: fail if conf supplied is not on {{ inventory_hostname }}
fail:
- name: Fail if conf supplied is not on {{ inventory_hostname }}
ansible.builtin.fail:
msg: |
The conf file '{{ conf }}' can not be found on {{ inventory_hostname }}
when:
Expand All @@ -115,26 +115,26 @@
gather_facts: false
tasks:

- name: import_role ceph_defaults
import_role:
- name: Import_role ceph_defaults
ansible.builtin.import_role:
name: ceph_defaults

- name: slurp the keyring
slurp:
- name: Slurp the keyring
ansible.builtin.slurp:
src: "{{ keyring }}"
register: client_keyring
no_log: true

- name: slurp the conf if it's supplied
slurp:
- name: Slurp the conf if it's supplied
ansible.builtin.slurp:
src: "{{ conf }}"
register: ceph_config
when:
- conf is defined
- conf | length > 0

- name: create minimal conf as a default
command: cephadm shell -- ceph config generate-minimal-conf
- name: Create minimal conf as a default
ansible.builtin.command: cephadm shell -- ceph config generate-minimal-conf
register: minimal_ceph_config
when: conf is undefined

Expand All @@ -145,26 +145,26 @@
gather_facts: true
tasks:

- name: import_role ceph_defaults
import_role:
- name: Import_role ceph_defaults
ansible.builtin.import_role:
name: ceph_defaults

- name: install ceph-common on rhel
command: dnf install --allowerasing --assumeyes ceph-common
- name: Install ceph-common on rhel
ansible.builtin.command: dnf install --allowerasing --assumeyes ceph-common
changed_when: false
register: result
until: result is succeeded
when: ansible_facts['os_family'] == 'RedHat'

- name: install ceph client prerequisites if needed
package:
- name: Install ceph client prerequisites if needed
ansible.builtin.package:
name: "{{ ceph_client_pkgs }}"
state: present
register: result
until: result is succeeded

- name: copy configuration and keyring files to the clients
copy:
- name: Copy configuration and keyring files to the clients
ansible.builtin.copy:
content: "{{ item.content }}"
dest: "{{ item.dest }}"
owner: ceph
Expand Down
26 changes: 13 additions & 13 deletions cephadm-distribute-ssh-key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,47 @@
become: true
gather_facts: false
tasks:
- name: fail if admin_node is not defined
fail:
- name: Fail if admin_node is not defined
ansible.builtin.fail:
msg: "You must set the variable admin_node"
run_once: true
delegate_to: localhost
when: admin_node is undefined

- name: get ssh public key from a file on the Ansible controller host
- name: Get ssh public key from a file on the Ansible controller host
when: cephadm_pubkey_path is defined
block:
- name: get details about {{ cephadm_pubkey_path }}
stat:
- name: Get details about {{ cephadm_pubkey_path }}
ansible.builtin.stat:
path: "{{ cephadm_pubkey_path }}"
register: cephadm_pubkey_path_stat
delegate_to: localhost
run_once: true

- name: fail if {{ cephadm_pubkey_path }} doesn't exist
fail:
- name: Fail if {{ cephadm_pubkey_path }} doesn't exist
ansible.builtin.fail:
msg: "{{ cephadm_pubkey_path }} doesn't exist or is invalid."
run_once: true
delegate_to: localhost
when:
- not cephadm_pubkey_path_stat.stat.exists | bool
or not cephadm_pubkey_path_stat.stat.isfile | bool

- name: get the cephadm ssh pub key
command: "cephadm shell {{ '--fsid ' + fsid if fsid is defined else '' }} ceph cephadm get-pub-key"
- name: Get the cephadm ssh pub key
ansible.builtin.command: "cephadm shell {{ '--fsid ' + fsid if fsid is defined else '' }} ceph cephadm get-pub-key"
changed_when: false
run_once: true
register: cephadm_get_pub_key
delegate_to: "{{ admin_node }}"
when: cephadm_pubkey_path is undefined

- name: allow ssh public key for {{ cephadm_ssh_user | default('root') }} account
authorized_key:
- name: Allow ssh public key for {{ cephadm_ssh_user | default('root') }} account
ansible.posix.authorized_key:
user: "{{ cephadm_ssh_user | default('root') }}"
key: "{{ lookup('file', cephadm_pubkey_path) if cephadm_pubkey_path is defined else cephadm_get_pub_key.stdout }}"

- name: set cephadm ssh user to {{ cephadm_ssh_user }}
command: "cephadm shell {{ '--fsid ' + fsid if fsid is defined else '' }} ceph cephadm set-user {{ cephadm_ssh_user | default('root') }}"
- name: Set cephadm ssh user to {{ cephadm_ssh_user }}
ansible.builtin.command: "cephadm shell {{ '--fsid ' + fsid if fsid is defined else '' }} ceph cephadm set-user {{ cephadm_ssh_user | default('root') }}"
changed_when: false
run_once: true
delegate_to: "{{ admin_node }}"
Loading

0 comments on commit 8ea6806

Please sign in to comment.