stackhpc / ansible-collection-cephadm

Apache License 2.0
16 stars 11 forks source link

Make cephadm_key module stateless #145

Closed m-bull closed 3 months ago

m-bull commented 6 months ago

This module should never write to files because they always exist inside the cephadm container, which is ephemeral. This change removes all file-writing functions and references to keyrings.

This fixes the following failure:

The full traceback is:                                                                                                                                                                                             
  File "/tmp/ansible_cephadm_key_payload_51gs4a3l/ansible_cephadm_key_payload.zip/ansible/module_utils/basic.py", line 688, in selinux_context                                                                     
    ret = selinux.lgetfilecon_raw(to_native(path, errors='surrogate_or_strict'))                                                                                                                                   
  File "/tmp/ansible_cephadm_key_payload_51gs4a3l/ansible_cephadm_key_payload.zip/ansible/module_utils/compat/selinux.py", line 95, in lgetfilecon_raw                                                             
    rc = _selinux_lib.lgetfilecon_raw(path, byref(con))                                                  
  File "/tmp/ansible_cephadm_key_payload_51gs4a3l/ansible_cephadm_key_payload.zip/ansible/module_utils/compat/selinux.py", line 23, in _check_rc                                                                   
    raise OSError(errno, os.strerror(errno))
failed: [oscephpor01] (item={'name': 'client.cinder', 'caps': {'mon': 'profile rbd', 'osd': 'profile rbd pool=volumes, profile rbd pool=vms, profile rbd-read-only pool=images', 'mgr': 'profile rbd pool=volumes, profile rbd pool=vms'}}) => changed=false                                                                
  ansible_loop_var: item                                                                                 
  invocation:                                                                                            
    module_args:                                                                                         
      attributes: null                                                                                   
      caps:                                                                                              
        mgr: profile rbd pool=volumes, profile rbd pool=vms                                              
        mon: profile rbd                                                                                 
        osd: profile rbd pool=volumes, profile rbd pool=vms, profile rbd-read-only pool=images           
      dest: /etc/ceph/                                                                                   
      group: null                                                                                        
      import_key: true                                                                                   
      mode: null                                                                                         
      name: client.cinder                                                                                                                                                                                          
      output_format: json                           
      owner: null                                                                                                                                                                                                  
      secret: ''                                    
      selevel: null                                                                                      
      serole: null                                                                                       
      setype: null                                                                                                                                                                                                 
      seuser: null                                                                                       
      state: present                                
      unsafe_writes: false                        
  item:                                                                                                  
    caps:                                                                                                
      mgr: profile rbd pool=volumes, profile rbd pool=vms                                                
      mon: profile rbd                              
      osd: profile rbd pool=volumes, profile rbd pool=vms, profile rbd-read-only pool=images             
    name: client.cinder                             
  msg: path /etc/ceph/ceph.client.cinder.keyring does not exist                                          
  path: /etc/ceph/ceph.client.cinder.keyring

Which is caused by module.set_fs_attributes_if_different running on the host when the keyring file is created in a previous step in an ephemeral cephadm container, and no longer exists.

This fixes a long-standing idempotency issue, where ceph keys can be created but the module fails on subsequent invocations. A side-effect of this change: the ability to specify and generate a secret string has been removed, and users should rely on retrieving the secret key from the cluster directly by registering the output from cephadm_key tasks.

m-bull commented 6 months ago

Thanks @mnasiadka - updated the changelog and role docs. I'm not sure fetch_initial_keys ever actually did anything, but we've deprecated it now anyway!

cityofships commented 3 months ago

I took the liberty of rebasing this

cityofships commented 3 months ago

Ideally needs a version bump in galaxy.yml too