Created
December 30, 2016 23:45
-
-
Save jeffbrl/ec59602e399553468147e6586502ae70 to your computer and use it in GitHub Desktop.
Ansible playbook to create ansible user on junos device with private key authentication
This file contains hidden or 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
system { | |
login { | |
user ansible { | |
class super-user; | |
authentication { | |
ssh-rsa "{{ ansible_public_key }}"; | |
} | |
} | |
} | |
} | |
This file contains hidden or 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
- name: Configure routers for ansible user with ssh key | |
hosts: all | |
connection: local | |
roles: | |
- Juniper.junos | |
vars: | |
ansible_public_key: "{{ lookup('file', '/home/ansible/.ssh/id_rsa.pub') }}" | |
vars_prompt: | |
- name: USER | |
prompt: Device user | |
private: no | |
- name: PASSWORD | |
prompt: Device password | |
private: yes | |
tasks: | |
- name: Build ansible user configuration | |
template: | |
src: ansible_user.conf.j2 | |
dest: ./ansible_user.conf | |
- name: Install config for ansible user on router | |
junos_install_config: | |
host={{ inventory_hostname }} | |
user={{ USER }} | |
passwd={{ PASSWORD }} | |
port=22 | |
file=ansible_user.conf | |
comment="Committed by ansible" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment