如何让Ansible在请求sudo密码之前显示主机名?
我有一个Ansible playbook来更新我基于Debian的服务器。出于简单性和安全性的考虑,我不想使用vault保存密码,也不想将密码存储在可公开访问的配置文件中。因此,我要求为每个具有如何让Ansible在请求sudo密码之前显示主机名?,ansible,Ansible,我有一个Ansible playbook来更新我基于Debian的服务器。出于简单性和安全性的考虑,我不想使用vault保存密码,也不想将密码存储在可公开访问的配置文件中。因此,我要求为每个具有 become: yes become_method: sudo 现在,当playbook运行时,Ansible做的第一件事似乎是询问sudo密码,但我不知道是哪台服务器(密码不同)有没有办法让Ansible在请求密码之前打印当前主机名? 更新剧本与此类似: --- - hosts: all
become: yes
become_method: sudo
现在,当playbook运行时,Ansible做的第一件事似乎是询问sudo密码,但我不知道是哪台服务器(密码不同)有没有办法让Ansible在请求密码之前打印当前主机名?
更新剧本与此类似:
---
- hosts:
all
gather_facts: no
vars:
verbose: false
log_dir: "log/dist-upgrade/{{ inventory_hostname }}"
pre_tasks:
- block:
- setup:
rescue:
- name: "Install required python-minimal package"
raw: "apt-get update && apt-get install -y --force-yes python-apt python-minimal"
- setup:
tasks:
- name: Update packages
apt:
update_cache: yes
upgrade: dist
autoremove: yes
register: output
- name: Check changes
set_fact:
updated: true
when: not output.stdout | search("0 upgraded, 0 newly installed")
- name: Display changes
debug:
msg: "{{ output.stdout_lines }}"
when: verbose or updated is defined
- block:
- name: "Create log directory"
file:
path: "{{ log_dir }}"
state: directory
changed_when: false
- name: "Write changes to logfile"
copy:
content: "{{ output.stdout }}"
dest: "{{ log_dir }}/dist-upgrade_{{ ansible_date_time.iso8601 }}.log"
changed_when: false
when: updated is defined
connection: local
(来源:)您的上述BENG配置不允许ansible向您询问BENG密码:它只是建议将BENG与sudo方法一起使用(例如,如果您配置了正确的密钥,则无需任何密码即可使用) 如果要求您输入密码,那是因为(这是一个猜测,但我很有信心……)您在运行
ansible playbook
时使用了--ask been pass
选项
在这种情况下,playbook操作开始时只会提示您一次,并且此默认密码将在您连接到的所有服务器上使用,除非您在资源清册中为特定主机/组定义了其他服务器
如果您有不同的密码,这取决于您的机器,您实际上没有其他选择:您需要在库存中声明这些密码(强烈建议使用ansible vault加密)或使用其他机制将其从外部应用程序(hashicorp vault、dynamic inventory、cyberark…)中取出是的,我使用--ask-been-pass。这有点含蓄。谢谢你的回答,即使Ansible不支持这一点让人非常失望。