Project

General

Profile

Tâche #31751

Scénario #31564: Définir la méthode pour renommer la clé du minion

Tester le renommage du minion avec la méthode proposée

Added by Daniel Dehennin 4 months ago. Updated 3 months ago.

Status:
Fermé
Priority:
Normal
Assigned To:
Start date:
02/25/2021
Due date:
% Done:

100%

Remaining (hours):
0.0

Description

Mettre en place une infrastructure pour tester https://gist.github.com/max-arnold/8a077ae67d3ab2faaf1bef0e9094b146

History

#1 Updated by Daniel Dehennin 4 months ago

  • Status changed from Nouveau to En cours
  • Assigned To set to Daniel Dehennin

Pour tester :

  1. Configurer module.run pour prendre la nouvelle syntaxe
  2. Créer le fichier /srv/salt/rename_win.sls contenant :
    # Save into salt://rename_win.sls then run the following command:
    # salt-run state.orch rename_win pillar='{"old": "OLD_NAME", "new": "NEW_NAME"}'
    #
    # For more tips like this, follow https://salt.tips
    
    {% set old_name = pillar['old'] %}
    {% set new_name = pillar['new'] %}
    
    Rename minion id:
      salt.function:
        - name: file.write
        - tgt: '{{ old_name }}'
        - arg:
            - 'C:\\salt\\conf\\minion_id'
            - '{{ new_name }}'
    
    Restart minion:
      salt.function:
        - name: cmd.run
        - tgt: '{{ old_name }}'
        - arg:
            - 'C:\\salt\\salt-call.bat service.restart salt-minion'
        - kwarg:
            bg: true
        - onchanges:
          - salt: Rename minion id
    
    Rename minion key:
      module.run:
        - file.rename:
            - '/etc/salt/pki/master/minions/{{ old_name }}'
            - '/etc/salt/pki/master/minions/{{ new_name }}'
        - onchanges:
          - salt: Rename minion id
          - salt: Restart minion
    
  3. Exécuter la commande suivante :
    salt-run state.orch rename_win pillar='{"old": "PC-513654.dompedago.etb1.lan", "new": "PC-bidule.dompedago.etb1.lan"}'
    

Cela donne le résultat :

scribe.dompedago.etb1.lan_master:
----------
          ID: Rename minion id
    Function: salt.function
        Name: file.write
      Result: True
     Comment: Function ran successfully. Function file.write ran on PC-513654.dompedago.etb1.lan.
     Started: 16:18:45.643764
    Duration: 1956.698 ms
     Changes:   
              PC-513654.dompedago.etb1.lan:
                  Wrote 1 lines to "C:\\salt\\conf\\minion_id" 
----------
          ID: Restart minion
    Function: salt.function
        Name: cmd.run
      Result: True
     Comment: Function ran successfully. Function cmd.run ran on PC-513654.dompedago.etb1.lan.
     Started: 16:18:47.600851
    Duration: 1971.687 ms
     Changes:   
              PC-513654.dompedago.etb1.lan:
----------
          ID: Rename minion key
    Function: module.run
      Result: True
     Comment: file.rename: True
     Started: 16:18:49.574036
    Duration: 7.25 ms
     Changes:   
              ----------
              file.rename:
                  True

Summary for scribe.dompedago.etb1.lan_master
------------
Succeeded: 3 (changed=3)
Failed:    0
------------
Total states run:     3
Total run time:   3.936 s

Nous voyons ensuite la clef modifiée :

root@scribe:~# salt-key 
Accepted Keys:
PC-bidule.dompedago.etb1.lan
Denied Keys:
Unaccepted Keys:
Rejected Keys:

#2 Updated by Daniel Dehennin 4 months ago

  • Status changed from En cours to Résolu
  • % Done changed from 0 to 100

#3 Updated by Laurent Flori 3 months ago

  • Status changed from Résolu to Fermé
  • Remaining (hours) set to 0.0

Also available in: Atom PDF