加解密現有檔案

  1. 建立明文檔 vfile1.yml。
    [deyu1@kvm19 ansible]$ echo 'vault file 1' > vfile1.yml
    
    [deyu1@kvm19 ansible]$ cat vfile1.yml
    vault file 1
    
  2. encrypt 加密 vfile1.yml,輸入兩次密碼,成功加密。
    [deyu1@kvm19 ansible]$ ansible-vault encrypt vfile1.yml
    New Vault password: 
    Confirm New Vault password: 
    Encryption successful
    
  3. 查看加密檔 vfile.yml,是一串亂數。
    [deyu1@kvm19 ansible]$ cat vfile1.yml
    $ANSIBLE_VAULT;1.1;AES256
    34363335623235366262323232303833623665643131313030626661616463636234303135353832
    6338376236373766613538326564376266303066626435330a663536393138346631386632353033
    32383232666461343039376136333464383438626439326237346164633866323931363964656137
    6264323737333234660a623139643162333734636235346464323131356632626534373737616633
    6337
    
  4. view 輸入密碼後,才可以檢視加密檔 vfile1.yml。
    [deyu1@kvm19 ansible]$ ansible-vault view vfile1.yml
    Vault password: 
    vault file 1
    
  5. decrypt 解密 vfile1.yml,輸入密碼,成功解密。
    [deyu1@kvm19 ansible]$ ansible-vault decrypt vfile1.yml
    Vault password: 
    Decryption successful
    
    [deyu1@kvm19 ansible]$ cat vfile1.yml
    vault file 1