Skip to content

Commit

Permalink
Update users: add server pick-list (trailofbits#1441)
Browse files Browse the repository at this point in the history
* 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'
  • Loading branch information
TC1977 authored and jackivanov committed May 21, 2019
1 parent a87b4c8 commit ecb4e55
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ecb4e55

Please sign in to comment.