yun install ansible
ansible-galaxy install Juniper.junos
ansible-galaxy list
ansible --version ansible 2.3.1.0 config file = /etc/ansible/ansible.cfg configured module search path = Default w/o overrides python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
[defaults] inventory = /etc/ansible/hosts host_key_checking = False log_path = /var/log/ansible.log
[testswitches] #SWTEST 192.168.8.192 #SWAC_0901 192.168.8.218 [prodswitches] #SWAC_1301 192.168.8.81 #SWAC_1302 192.168.8.82 [allswitches:children] testswitches prodswitches
#playbook --- --- # - name: Juniper Config Changes # , playbook hosts: testswitches #, - Juniper, roles: - Juniper.junos connection: local gather_facts: no # Python, vars: ansible_python_interpreter: /usr/bin/python # , playbook vars_prompt: - name: USERNAME prompt: Username private: no - name: PASSWORD prompt: Password private: yes # , #timeout 120 , commit EX2200 , tasks: - name: Retrieve information from devices running Junos OS junos_config: host: "{{ inventory_hostname }}" username: "{{ USERNAME }}" password: "{{ PASSWORD }}" timeout: 120 port: 22 # , lines: - delete interfaces vme unit 0 family inet dhcp - set vlans vlan10 description "TestVlan" - set vlans vlan10 vlan-id 10
Username: admin Password: PLAY [Juniper Config Changes] ********************************************** TASK [Retrieve information from devices running Junos OS] ok: [192.168.8.218] changed: [192.168.8.192] PLAY RECAP ****************************************************** 192.168.8.192 : ok=1 changed=1 unreachable=0 failed=0 192.168.8.218 : ok=1 changed=0 unreachable=0 failed=0
* [edit vlans vlan10] - description SRV; + description "TestVlan"; + vlan-id 10; changed: [192.168.8.192] ok: [192.168.8.218]
tasks: - name: Retrieve information from devices running Junos OS junos_command: host: "{{ inventory_hostname }}" username: "{{ USERNAME }}" password: "{{ PASSWORD }}" timeout: 120 port: 22 commands: - show version # , , register: printout - name: Save Output #debug: msg="{{printout.stdout_lines}}" lineinfile: path: versions.log create: yes line: "{{printout.stdout_lines}}"
Source: https://habr.com/ru/post/343682/
All Articles