大网数据广告活动
服务器运维问答

How to hide password in the ansible host file

· 52CE 我爱测

I have some windows hosts are configured with WinRM in order to let Ansible connect them. Not like Linux hosts can do ssh-copy-id to avoid entering the credentials, I have to put my admin password in the /etc/ansible/host in orde…

问题原文

原帖链接 · ITnewbie · CC BY-SA 4.0

I have some windows hosts are configured with WinRM in order to let Ansible connect them. Not like Linux hosts can do ssh-copy-id to avoid entering the credentials, I have to put my admin password in the /etc/ansible/host in order to connect these windows machines:

cat /etc/ansible/hosts

[win]
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4

[win:vars]
ansible_user= administrator
ansible_password=mypasswd
ansible_port=5986
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore

Is there any way to avoid having the plain-text password in the hosts file?

I am very new to Ansible, any help is appreciated!

已采纳解答

原帖链接 · John Mahowald · CC BY-SA 4.0

Decide what you want to use for secrets management on the machine running Ansible.

lookup plugins which get data from some system. ansible-doc -t lookup --list and review the list, secrets related ones tend to have "pass" or "secret" in the name. Or "keyring" which wraps the local OS secret storage (GNOME secret service, KDE kwallet).

After configuring whatever secrets system, refer to it in Ansible with a lookup expression:

ansible_password="{{ lookup('keyring', secret_name) }}"

The other option is ansible-vault, the integrated file encryption utility. (Note this is different from HashiCorp vault, which if you had you could use with its lookup plugin.) For this you could encrypt the inventory file, or a separate vars file you put the secrets.


Bonus tip: /etc/ansible/hosts is merely the default inventory file. You can change the default inventory file in ansible.cfg. Or provide one on the command line with with -i option. So you can have inventory in your home directory, and edit it without touching privilaged directories.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-04-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。