-
-
Notifications
You must be signed in to change notification settings - Fork 609
/
main.yml
29 lines (25 loc) · 1.21 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
---
- name: Require manual definition of remote-user
fail:
msg: |
When using `--ask-pass` option, use `-u` option to define remote-user:
ansible-playbook server.yml -e env={{ env | default('production') }} -u root --ask-pass
when: ansible_user is not defined and cli_ask_pass | default(false)
- name: Check whether Ansible can connect as root
local_action: command ansible {{ inventory_hostname }} -m raw -a whoami -u root {{ cli_options | default('') }}
failed_when: false
changed_when: false
register: root_status
tags: [connection-tests]
- name: Set remote user for each host
set_fact:
ansible_user: "{{ ('root' in root_status.stdout_lines) | ternary('root', admin_user) }}"
when: ansible_user is not defined
- name: Announce which user was selected
debug:
msg: "Note: Ansible will attempt connections as user = {{ ansible_user }}"
- name: Load become password
set_fact:
ansible_become_pass: "{% for user in vault_users | default([]) if user.name == ansible_user and user.password is defined %}{% if loop.first %}{{ user.password }}{% endif %}{% endfor %}"
when: ansible_user != 'root' and not cli_ask_become_pass | default(false) and ansible_become_pass is not defined
no_log: true