Update users: add server pick-list (#1441)

* Pick server to update from menu

* Command instead of shell

* Move to find module

Switched to the find module, and made the whole block dependent on server being undefined.

* Change names

* users.yml update
- Add assert to check if any servers found
- Set server_list as a proper list

* Change 'Build string' to 'Build list'
This commit is contained in:
TC1977 2019-05-21 11:17:58 -04:00 committed by Jack Ivanov
parent a87b4c8a87
commit ecb4e555b4

View file

@ -7,17 +7,44 @@
tasks:
- block:
- name: Get list of installed config files
find:
paths: configs/
depth: 2
recurse: true
hidden: true
patterns: ".config.yml"
register: _configs_list
- name: Verify servers
assert:
that: _configs_list.matched > 0
msg: No servers found, nothing to update.
- name: Build list of installed servers
set_fact:
server_list: >-
[{% for i in _configs_list.files %}
'{{ i.path.split('/')[1] }}'
{{ ',' if not loop.last else '' }}
{% endfor %}]
- name: Server address prompt
pause:
prompt: "Enter the IP address of your server: (or use localhost for local installation)"
prompt: |
Select the server to update user list below:
{% for r in server_list %}
{{ loop.index }}. {{ r }}
{% endfor %}
register: _server
when: server is undefined
when: server is undefined
- block:
- name: Set facts based on the input
set_fact:
algo_server: >-
{% if server is defined %}{{ server }}
{%- elif _server.user_input %}{{ _server.user_input }}
{%- elif _server.user_input %}{{ server_list[_server.user_input | int -1 ] }}
{%- else %}omit{% endif %}
- name: Import host specific variables