Skip to content

Commit

Permalink
setup sonic via ztp only
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar committed Nov 13, 2024
1 parent 0d5b93c commit 76d2ba5
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 47 deletions.
22 changes: 12 additions & 10 deletions partition/roles/ztp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ Configures a server for providing zero-touch-provisioning scripts for switches.

## Variables

| Name | Mandatory | Description |
| -------------------- | --------- | ----------------------------------------------------------- |
| ztp_nginx_image_name | yes | the docker image to use to serve ztp scripts. |
| ztp_nginx_image_tag | yes | the tag of the docker image to use to serve ztp scripts. |
| ztp_host_dir_path | | the path to serve ztp scripts from. |
| ztp_listen_address | | the address used to serve ztp requests |
| ztp_port | | the port to serve ztp scripts on. |
| ztp_authorized_keys | yes | the authorized keys that should be installed by ztp. |
| ztp_admin_user | | the user for which the authorized keys will be provisioned. |
| ztp_additional_files | | puts additional files into serve directory. |
| Name | Mandatory | Description |
| ----------------------- | --------- | ------------------------------------------------------------ |
| ztp_nginx_image_name | yes | the docker image to use to serve ztp scripts. |
| ztp_nginx_image_tag | yes | the tag of the docker image to use to serve ztp scripts. |
| ztp_host_dir_path | | the path to serve ztp scripts from. |
| ztp_listen_address | | the address used to serve ztp requests |
| ztp_port | | the port to serve ztp scripts on. |
| ztp_authorized_keys | yes | the authorized keys that should be installed by ztp. |
| ztp_admin_user | | the user for which the authorized keys will be provisioned. |
| ztp_additional_files | | puts additional files into serve directory. |
| ztp_sonic_nameservers | | the nameservers to put into resolv.conf for sonic |
| ztp_sonic_extended_cacl | | used to populate /etc/sonic/iptables.json for sonic switches |

## Provisioning SONiC Switches via ztp.json

Expand Down
5 changes: 5 additions & 0 deletions partition/roles/ztp/defaults/main/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ ztp_port: 8080
ztp_additional_files: []
# - name: foo.sh
# data: echo

ztp_sonic_nameservers: []
ztp_sonic_extended_cacl:
ipv4: []
ipv6: []
7 changes: 0 additions & 7 deletions partition/roles/ztp/files/config_db.json

This file was deleted.

3 changes: 0 additions & 3 deletions partition/roles/ztp/files/reload.sh

This file was deleted.

29 changes: 8 additions & 21 deletions partition/roles/ztp/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,16 @@
path: "{{ ztp_host_dir_path }}/config"
state: directory

- name: render ztp script
- name: render templates
template:
src: "ztp.sh.j2"
dest: "{{ ztp_host_dir_path }}/config/ztp.sh"
mode: 0644

- name: copy config_db.json
copy:
src: "config_db.json"
dest: "{{ ztp_host_dir_path }}/config/config_db.json"
mode: 0644

- name: copy reload script
copy:
src: "reload.sh"
dest: "{{ ztp_host_dir_path }}/config/reload.sh"
mode: 0644

- name: render ztp.json
template:
src: "ztp.json.j2"
dest: "{{ ztp_host_dir_path }}/config/ztp.json"
src: "{{ item }}"
dest: "{{ ztp_host_dir_path }}/config/{{ item | splitext | first }}"
mode: 0644
loop:
- iptables.json.j2
- resolv.conf.j2
- ztp.json.j2
- ztp.sh.j2

- name: copy additional contents
copy:
Expand Down
25 changes: 19 additions & 6 deletions partition/roles/ztp/templates/ztp.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,30 @@
"url": "http://{{ ztp_listen_address }}:{{ ztp_port }}/ztp.sh"
}
},
"03-configdb-json": {
"03-additional-files": {
"url": {
"source": "http://{{ ztp_listen_address }}:{{ ztp_port }}/config_db.json"
"source": "http://{{ ztp_listen_address }}:{{ ztp_port }}/resolv.conf",
"destination": "/etc/resolv.conf"
},
"url": {
"source": "http://{{ ztp_listen_address }}:{{ ztp_port }}/iptables.json",
"destination": "/etc/sonic/iptables.json"
}
},
"04-configdb-json": {
"dynamic-url": {
"source": {
"prefix": "http://{{ ztp_listen_address }}:{{ ztp_port }}/",
"identifier": "hostname",
"suffix": "_config_db.json"
},
"clear-config": false
},
"04-reload": {
"plugin": {
"url": "http://{{ ztp_listen_address }}:{{ ztp_port }}/reload.sh"
}
{% if ztp_additional_files | selectattr('name', 'equalto', 'ztp-additional-script.sh') %}
"05-ztp-additional-script": {
"plugin": "http://{{ ztp_listen_address }}:{{ ztp_port }}/ztp-additional-script.sh",
},
{% endif %}
"restart-ztp-no-config": false
}
}

0 comments on commit 76d2ba5

Please sign in to comment.