Initial commit, squashed
This commit is contained in:
commit
158e8740b8
83 changed files with 2718 additions and 0 deletions
6
roles/access/handlers/main.yml
Normal file
6
roles/access/handlers/main.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
- name: write config
|
||||
ansible.netcommon.cli_command:
|
||||
command: "copy running-config startup-config"
|
||||
prompt: "Destination filename startup-config\\? \\[y/n\\]: "
|
||||
answer: "y"
|
||||
when: "'handler' not in ansible_skip_tags"
|
7
roles/access/tasks/main.yml
Normal file
7
roles/access/tasks/main.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
- name: Set configuration
|
||||
ansible.netcommon.cli_config:
|
||||
config: "{{ lookup('template', 'config.j2') }}"
|
||||
register: result
|
||||
# These lines are not displayed by 'sho ru' and always reported as different, so ignore them.
|
||||
changed_when: result.commands | reject('match', '^(no shutdown|no switchport access vlan|switchport mode hybrid|interface .*)$')
|
||||
notify: write config
|
68
roles/access/templates/config.j2
Normal file
68
roles/access/templates/config.j2
Normal file
|
@ -0,0 +1,68 @@
|
|||
terminal length default 0
|
||||
!
|
||||
line console
|
||||
!
|
||||
line telnet
|
||||
!
|
||||
line ssh
|
||||
!
|
||||
port-channel load-balance src-dst-ip
|
||||
!
|
||||
ip ssh server
|
||||
ssh user admin authentication-method publickey /c:/ansible.pub
|
||||
!
|
||||
vlan {{ vlans | map(attribute='vid') | vlan_parser | join(',') }}
|
||||
!
|
||||
{% for iface in interfaces | selectattr('enabled') | selectattr('lag') %}
|
||||
interface {{ iface.name }}
|
||||
channel-group 1 mode active
|
||||
!
|
||||
{% endfor %}
|
||||
{% set mgmt = namespace(ip=false, gw=false) %}
|
||||
{% for iface in interfaces | rejectattr('lag') %}
|
||||
interface {{ iface.name }}
|
||||
{% if iface.enabled and iface.mode %}
|
||||
{% if iface.type.value != 'lag' %}
|
||||
no shutdown
|
||||
{% endif %}
|
||||
{% if iface.mgmt_only and iface.ip_addresses %}
|
||||
{% set mgmt.ip = iface.ip_addresses[0].address %}
|
||||
{% if iface.custom_fields.gateway %}
|
||||
{% set mgmt.gw = iface.custom_fields.gateway.address %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if iface.mode.value == 'access' %}
|
||||
switchport mode access
|
||||
{% if iface.untagged_vlan and iface.untagged_vlan.vid != 1 %}
|
||||
switchport access vlan {{ iface.untagged_vlan.vid }}
|
||||
{% else %}
|
||||
no switchport access vlan
|
||||
{% endif %}
|
||||
{% elif iface.mode.value == 'tagged' %}
|
||||
switchport mode trunk
|
||||
switchport trunk allowed vlan {{ (iface.tagged_vlans or vlans) | map(attribute='vid') | vlan_parser | join(',') }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
shutdown
|
||||
{% endif %}
|
||||
!
|
||||
{% endfor %}
|
||||
{% if mgmt.ip %}
|
||||
interface Vlan1
|
||||
ip address {{ mgmt.ip | ipaddr('address') }} {{ mgmt.ip | ipaddr('netmask') }}
|
||||
{% endif %}
|
||||
!
|
||||
sntp enable
|
||||
{% for address in ntp %}
|
||||
sntp server {{ address }}
|
||||
{% endfor %}
|
||||
!
|
||||
ntp access-group default nomodify noquery
|
||||
!
|
||||
{% if mgmt.gw %}
|
||||
ip route 0.0.0.0 0.0.0.0 {{ mgmt.gw | ipaddr('address') }} primary
|
||||
{% endif %}
|
||||
!
|
||||
no ddp
|
||||
!
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue