【发布时间】:2020-04-28 00:48:12
【问题描述】:
我有一个 Ansible 手册来更新我基于 Debian 的服务器。出于简单和安全的原因,我不想使用保管库来保存密码,也不想将它们存储在可公开访问的配置文件中。所以我用
询问每个客户的密码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
(来源:http://www.panticz.de/Debian-Ubuntu-mass-dist-upgrade-with-Ansible)
【问题讨论】:
标签: ansible