Start coverting the network users playbook to use loops and new key

This commit is contained in:
Ethan Paul 2019-09-02 19:54:35 -04:00
parent 2b7cb022da
commit 69697ef58c

View File

@ -1,10 +1,8 @@
--- ---
- hosts: router - hosts: router.net.enp.one
name: Configure users on router name: Configure users on router
connection: network_cli connection: network_cli
gather_facts: false gather_facts: false
vars:
ansible_network_os: edgeos
tasks: tasks:
- import_tasks: tasks/users-preprocessing.yml - import_tasks: tasks/users-preprocessing.yml
@ -14,8 +12,7 @@
- set system login user {{ item.name }} authentication encrypted-password "{{ item.password }}" - set system login user {{ item.name }} authentication encrypted-password "{{ item.password }}"
- set system login user {{ item.name }} full-name "{{ item.fullname if item.fullname is defined else "" }}" - set system login user {{ item.name }} full-name "{{ item.fullname if item.fullname is defined else "" }}"
- set system login user {{ item.name }} level {{ 'operator' if item.name != 'ansible' else 'admin' }} - set system login user {{ item.name }} level {{ 'operator' if item.name != 'ansible' else 'admin' }}
with_items: loop: "{{ local_users | difference([None]) }}"
- "{{ local_users | difference([None]) }}"
- name: Grant administrative access to admin users - name: Grant administrative access to admin users
edgeos_config: edgeos_config:
@ -25,15 +22,13 @@
- "{{ local_admin_users | difference([None]) }}" - "{{ local_admin_users | difference([None]) }}"
- name: Assemble loadkey files - name: Assemble loadkey files
copy: edgeos_command:
src: keys/{{ item }} commands:
dest: /tmp - sudo tee "{{ item.sshkeys | join('\n') }}"<<</tmp/{{ item.name }}.keys
with_items: loop: "{{ local_admin_users | difference([None]) }}"
- "{{ local_admin_users | difference([None]) }}"
- name: Load keys - name: Load keys
edgeos_config: edgeos_config:
lines: lines:
- loadkey {{ item }} /tmp/{{ item }}/*.pub - loadkey {{ item }} /tmp/{{ item }}.keys
with_items: loop: "{{ local_admin_users | difference([None]) }}"
- "{{ local_admin_users | difference([None]) }}"