Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

playbook

TiTom edited this page Nov 22, 2016 · 1 revision

3. Playbooks

Repository provides some different playbooks for example purpose. Available playbooks are listed below:

3.1 Install ZTP software requirements

A playbook to install all software on the remote ZTP server has been created. It will execute bootstraping to configure Python and then install following packages:

  • isc-dhcp-server
  • vsftpd

This playbook is for Debian like system and has been validated with Ubuntu 16.04 LTS

3.2 Create directory structure

A playbook has been created to clean / initiate local directory structure to store all requested files before pushing them to any ZTP server. Playbook is named playbook-ztp-init.yml. Actions are listed below:

  • Check if build_dir exists
  • Delete build_dir if it exists
  • Create build_dir
  • Create children directory to store softwares and configuration as well
ansible-playbook -i hosts.ini playbook-ztp-init.yml

PLAY [Init ZTP directory strucutre to store local files] ***********************

TASK [ztp-init : Print build path version] *************************************
ok: [ansible01] => {
   "msg": "Build directory conf/ztp"
}

TASK [ztp-init : Check if path exists] *****************************************
ok: [ansible01]

TASK [ztp-init : It exists] ****************************************************
ok: [ansible01] => {
   "msg": "Yay, the path exists! will delete it"
}

TASK [ztp-init : Remove build_dir] *********************************************
changed: [ansible01]

TASK [ztp-init : It doesn't exist] *********************************************
skipping: [ansible01]

TASK [ztp-init : create ztp directory] *****************************************
changed: [ansible01]

TASK [ztp-init : build_dir created] ********************************************
ok: [ansible01] => {
   "msg": "build_dir has been initiated correctly"
}

TASK [ztp-init : create ztp directory for configlet] ***************************
changed: [ansible01]

TASK [ztp-init : create ztp directory for softwares] ***************************
changed: [ansible01]

PLAY RECAP *********************************************************************
ansible01                  : ok=8    changed=4    unreachable=0    failed=0

3.3 Create configuration for devices

As ZTP provides a way to push configuration to devices, this playbook use a role to create basic default configuration based on data configured in your inventory and in any yaml files under group_vars and/or host_vars.

ansible-playbook playbook-junos-conf-generate.yml

PLAY [Populate local deivces configuration] ************************************

TASK [junos-conf-generator : Building common configuration for junos devices] **
ok: [FR-EX2200-110]
ok: [FR-EX2200-112]
ok: [FR-EX2200-111]

PLAY RECAP *********************************************************************
FR-EX2200-110              : ok=1    changed=0    unreachable=0    failed=0
FR-EX2200-111              : ok=1    changed=0    unreachable=0    failed=0
FR-EX2200-112              : ok=1    changed=0    unreachable=0    failed=0

This playbook built configuration by using role junos-conf-generator

3.4 Generate

Even without real devices, it's possible to regenerate configurations for all devices using ansible playbooks provided with the project

You can generate configurations by using the following playbook:

ansible-playbook -i hosts.ini playbook-ztp-conf-generate.yml

By default, all configurations generated will be stored under the directory conf/ztp as defined by {{build_dir}} and will replace existing configuration store there

The output below is an example based:

ansible-playbook -i hosts.ini playbook-ztp-conf-generate.yml

PLAY [Populate local ZTP configurations] ***************************************

TASK [ztp-create-config : building basic dhcp configuration] *******************
ok: [ztp01]
changed: [srx-02]
ok: [srx-01]
ok: [ansible01]

TASK [ztp-create-config : building ztp configuration for dhcp server] **********
skipping: [ztp01]
skipping: [ansible01]
changed: [srx-02]
changed: [srx-01]

TASK [ztp-create-config : assemble dhcp configuration] *************************
ok: [ztp01]
changed: [srx-02]
ok: [ansible01]
ok: [srx-01]

PLAY RECAP *********************************************************************
ansible01                  : ok=2    changed=0    unreachable=0    failed=0
srx-01                     : ok=3    changed=1    unreachable=0    failed=0
srx-02                     : ok=3    changed=3    unreachable=0    failed=0
ztp01                      : ok=2    changed=0    unreachable=0    failed=0

3.5 Complete ZTP workflow

A complete ZTP workflow is providing in the playbook named playbook-ztp.yml. This playbook executes all the following actions:

  • Install dhcp and ftp servers on the remote servers
  • Configure FTP server
  • Generate DHCP configuration with all global parameters
  • Generate DHCP configuration for all hosts defined in your inventory
  • Push DHCP configuration and reload the service
  • Push devices' configuration within the FTP server

You can execute this playbook by using the following playbook:

ansible-playbook -i hosts.ini playbook-ztp.yml

By default, all configurations generated will be stored under the directory conf/ztp and will replace existing configuration store there

3.6 Push data to ZTP servers.

This playbook will push all data to your remote servers by using basic copy statement or by using synchronize module. Default mode is to use copy and an example is provided below:

ansible-playbook playbook-ztp-push-data.yml

PLAY [Send ZTP configurations & softwares to server] ***************************

TASK [ztp-push-dhcp : Push junos configuration to the FTP server with sync] ****
skipping: [ztp01]

TASK [ztp-push-dhcp : Push junos configuration to the FTP server] **************
changed: [ztp01] => (item=/home/tom/scripting/ansible-junos-ztp/conf/FR-EX2200-112.conf)
changed: [ztp01] => (item=/home/tom/scripting/ansible-junos-ztp/conf/FR-EX2200-110.conf)
changed: [ztp01] => (item=/home/tom/scripting/ansible-junos-ztp/conf/FR-EX2200-111.conf)

TASK [ztp-push-dhcp : Push junos softwares to the FTP server] ******************

TASK [ztp-push-dhcp : Copy dhcp content to dhcp-server] ************************
ok: [ztp01]

TASK [ztp-push-dhcp : Restart dhcp service to apply changes] *******************
skipping: [ztp01]

If you want to use synchronize module, you have to install rsync on your local machine. Installation and configuration of rsync on remote ZTP servers is supported by role ztp-install-packages. Then, to activate this module, you have to set sync variable to true in your playbook:

---
  ### Send files to ZTP servers
  - name: Send ZTP configurations & softwares to server
    hosts: ztp-servers
    connection: ssh
    gather_facts: no
    roles:
      - {role: ztp-push-dhcp, become: yes, sync: true}

As synchronize module relies on rsync, authentication must be configured out of this playbook. You can use ssh-keys to avoid password prompt or you will have to enter your password when playbook will upload files.