差異處
這裏顯示兩個版本的差異處。
兩邊的前次修訂版 前次修改 下次修改 | 前次修改 | ||
tech:ansible [2023/09/03 00:47] – jonathan | tech:ansible [2023/12/29 17:40] (目前版本) – jonathan | ||
---|---|---|---|
行 44: | 行 44: | ||
</ | </ | ||
* 簡單驗證 <cli> | * 簡單驗證 <cli> | ||
- | $ ansible all -i test.yaml --list-hosts | + | $ ansible all -i inventory.yaml --list-hosts |
hosts (2): | hosts (2): | ||
aac | aac | ||
行 87: | 行 87: | ||
when: reboot_required_file.stat.exists | when: reboot_required_file.stat.exists | ||
</ | </ | ||
- | * 執行命令 <cli> | + | * 驗證執行命令(**加上 --check**) |
ansible-playbook -i inventory.yaml upgrade.yaml -e ansible_python_interpreter=/ | ansible-playbook -i inventory.yaml upgrade.yaml -e ansible_python_interpreter=/ | ||
</ | </ | ||
行 123: | 行 123: | ||
</ | </ | ||
+ | ===== 常見問題 ===== | ||
+ | ==== 1. 如何對 ansible_ssh_pass 這類登入密碼進行加密 ==== | ||
+ | * 使用 ansible-vault encrypt_string 登入密碼 --ask-vault-pass 方式來對要保護的密碼 Exp. MyPassword 產生加密, | ||
+ | $ ansible-vault encrypt_string MyPassword --ask-vault-pass | ||
+ | New Vault password: KeyPass | ||
+ | Confirm New Vault password: KeyPass | ||
+ | !vault | | ||
+ | $ANSIBLE_VAULT; | ||
+ | 63613230353861653733633761663630643564323330613263343061656163383731386364666366 | ||
+ | 3430303131616563616634386130613461636433383730360a663130653463313465623837373335 | ||
+ | 61336333643663343535396339633165653334336236363032613130636537336664646535666666 | ||
+ | 3863306137663763610a313034383233626563336365303431313564316338653363636432386438 | ||
+ | 3736 | ||
+ | Encryption successful | ||
+ | </ | ||
+ | * 將這加密後的內容取代 ansible_ssh_pass 原本的明碼部分 Exp. < | ||
+ | : | ||
+ | hosts: | ||
+ | aac: | ||
+ | ansible_host: | ||
+ | ansible_ssh_pass: | ||
+ | : | ||
+ | </ | ||
+ | : | ||
+ | hosts: | ||
+ | aac: | ||
+ | ansible_host: | ||
+ | ansible_ssh_pass: | ||
+ | $ANSIBLE_VAULT; | ||
+ | 63613230353861653733633761663630643564323330613263343061656163383731386364666366 | ||
+ | 3430303131616563616634386130613461636433383730360a663130653463313465623837373335 | ||
+ | 61336333643663343535396339633165653334336236363032613130636537336664646535666666 | ||
+ | 3863306137663763610a313034383233626563336365303431313564316338653363636432386438 | ||
+ | 3736 | ||
+ | : | ||
+ | </ | ||
+ | * 然後執行 ansible-playbook 後面必須加上 **--ask-vault-pass** 才會彈出讓你輸入解密密碼 Exp. KeyPass< | ||
+ | $ ansible-playbook -i inventory.yaml upgrade.yaml --ask-vault-pass | ||
+ | Vault password: KeyPass | ||
+ | |||
+ | PLAY [servers] ****************************************************************************************************************************************************************************** | ||
+ | |||
+ | TASK [Gathering Facts] ********************************************************************************************************************************************************************** | ||
+ | ok: [nuc] | ||
+ | : | ||
+ | </ | ||
+ | * 也可以執行 ansible-playbook 後面加上 **--vault-password-file** 指定解密密碼檔案 Exp. .vault_pass< | ||
+ | $ ansible-playbook -i inventory.yaml upgrade.yaml --vault-password-file ./ | ||
+ | </ | ||
===== 參考網址 ===== | ===== 參考網址 ===== | ||
* https:// | * https:// | ||
行 128: | 行 177: | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
- | {{tag> | + | {{tag>ansible |