Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Created December 30, 2016 23:45
Show Gist options
  • Save jeffbrl/ec59602e399553468147e6586502ae70 to your computer and use it in GitHub Desktop.
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
system {
login {
user ansible {
class super-user;
authentication {
ssh-rsa "{{ ansible_public_key }}";
}
}
}
}
- 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