-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
major_changes: | ||
- prompt_password - initial commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
release_summary: | | ||
| Release Date: 2023-03-09 | ||
| Initial release of the password_prompt role |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
TODO: test with multiple hosts | ||
|
||
# Ansible role: huyz.general.password_prompt | ||
|
||
Prompts for the `ansible_password` if not defined, with the option to also set the `ansible_become_password` if not defined. | ||
|
||
This avoids the need to call `ansible-playbook` with `--ask-pass` and `--ask-become-pass`. | ||
|
||
## Installation | ||
|
||
This repo uses the FQCN convention. | ||
|
||
Include the collection in the Ansible Galaxy `requirements.yml`: | ||
|
||
```shell | ||
--- | ||
collections: | ||
- name: huyz.general | ||
``` | ||
|
||
You can then include the role `huyz.general.prompt_password`. | ||
|
||
## Example | ||
|
||
```yaml | ||
- name: Prompt for ansible_password if needed | ||
ansible.builtin.include_role: | ||
name: huyz.generalprompt_password | ||
vars: | ||
copy_to_become_password: true | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Accepts vars: | ||
# - copy_to_become_password: true to automatically set `become_password` | ||
# as well (if not yet defined). | ||
--- | ||
- name: Prompt for ssh password if necessary | ||
when: ansible_password is undefined | ||
block: | ||
- name: Conditionally prompt for ssh password | ||
ansible.builtin.pause: | ||
prompt: "Password for {{ ansible_user_id | d('unknown') }}@{{ ansible_host | d('unknown') }}" | ||
echo: false | ||
register: password_prompt | ||
no_log: true | ||
|
||
- name: Set ansible_password | ||
ansible.builtin.set_fact: | ||
ansible_password: "{{ password_prompt.user_input }}" | ||
no_log: true | ||
|
||
- name: Set ansible_become_password | ||
ansible.builtin.set_fact: | ||
ansible_become_password: "{{ ansible_password }}" | ||
no_log: true | ||
when: copy_to_become_password | d(false) and ansible_become_password is undefined |