Automation

 View Only
last person joined: 6 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  Ansible playbook for config generation

    Posted 02-04-2022 05:35
    Good morning all,

    Im hoping some of you can assist here.
    i have recently joined a new organisation, and they are running ansible to generate config for new sites/devices etc - GREAT

    The ansible itself is linked in with other tools to pull information, i.e NetBox

    the problem i have is that the person who created the scripts etc no longer works here, so i am trying to piece together the existing playbook.

    this is what i have below:

    File structure
    ├── ansible.cfg
    ├── complete_config
    ├── inventory_directory
    │   ├── group_vars
    │   │   ├── example-site.yaml
    │   │   ├── xxxxxx.yaml
    │   │   └── junos.yaml
    │   ├── host
    │   ├── host_vars
    │   │   ├── devica-a.yaml
    │   │   ├── devica-b.yaml
    │   │   ├── xxxxx-srx.yaml
    │   │   └── xxxxx-switch.yaml
    │   └── hosts.yaml
    ├── ncg-ansible-templates
    │   ├── Readme.md
    │   ├── example-core-playbook.yaml
    │   ├── example-inventory
    │   │   ├── group_vars
    │   │   │   ├── xxxxx.yaml
    │   │   │   └── junos.yaml
    │   │   ├── host_vars
    │   │   │   ├── asw1.floor-gnd.xxxxx.sof69.gb.yaml
    │   │   │   └── csrx1.floor-gnd.xxxxx.sof69.gb.yaml
    │   │   └── hosts
    │   ├── example-playbook.yaml
    │   └── roles
    │   └── full_config
    │   └── templates
    │   ├── xxxxx-playbook.yaml
    │   ├── juniper-base-template-v2.j2
    │   ├── srx-base-template-v1.j2
    │   ├── srx-cluster-template-v1.j2
    │   ├── srx-cluster-template-v2.j2
    │   ├── srx-standalone-template-v1.j2
    │   ├── switch-template-v1.j2
    │   ├── switch-template-v2.j2
    │   └── tenant-core-config-template.j2
    └── netbox-provisioning
    ├── __pycache__
    │   └── netbox_allocate.cpython-38.pyc
    ├── ncg_netbox.py
    ├── netbox_allocate.py
    └── tests
    ├── conftest.py
    ├── docker
    │   ├── API_key.txt
    │   ├── configuration
    │   │   ├── configuration.py
    │   │   ├── gunicorn_config.py
    │   │   └── ldap_config.py
    │   ├── create-docker-env.sh
    │   ├── docker-compose.yml
    │   ├── initializers
    │   │   ├── custom_fields.yml
    │   │   ├── device_roles.yml
    │   │   ├── device_types.yml
    │   │   ├── devices.yml
    │   │   ├── groups.yml
    │   │   ├── manufacturers.yml
    │   │   ├── platforms.yml
    │   │   ├── rack_roles.yml
    │   │   ├── racks.yml
    │   │   ├── regions.yml
    │   │   ├── sites.yml
    │   │   └── users.yml
    │   ├── netbox.env
    │   ├── postgres.env
    │   ├── pytest_dump.sql
    │   ├── redis.env
    danr@DESKTOP-QU70IHU:~$
    │   ├── reports
    │   │   └── devices.py.example
    │   └── startup_scripts
    │   ├── 000_users.py
    │   ├── 010_groups.py
    │   ├── 020_custom_fields.py
    │   ├── 030_regions.py
    │   ├── 040_sites.py
    │   ├── 050_manufacturers.py
    │   ├── 060_device_types.py
    │   ├── 070_rack_roles.py
    │   ├── 080_racks.py
    │   ├── 090_device_roles.py
    │   ├── 100_platforms.py
    │   └── 110_devices.py
    ├── test_data.py
    └── test_netbox.py

    19 directories, 69 files

    when i run the ansible-playbook <site name playbook>.yaml it completes, but nothing is generated or output (or am i being blind)

    danr@DESKTOP-QU70IHU:~$ ansible-playbook /home/danr/ncg-ansible-templates/roles/full_config/templates/xxxxx-playbook.yaml

    PLAY [Config generation playbook] **************************************************************************************************************************

    TASK [Set destination directory] ***************************************************************************************************************************
    ok: [device-a]
    ok: [xxxxx-srx]
    ok: [device-b]
    ok: [xxxxx-switch]

    PLAY RECAP *************************************************************************************************************************************************
    device-a : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    device-b : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    xxxxx-srx : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    xxxxx-switch : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

    danr@DESKTOP-QU70IHU:~$

    my playbook currently has this - 
    - name: Config generation playbook
    hosts: all
    gather_facts: false
    tasks:
    - name: Set destination directory
    set_fact:
    dest_dir: ~/complete_config/

    Any assistance would be great on this.

    Many thanks
    Dan

    ------------------------------
    DAN RAWLINGS
    ------------------------------


  • 2.  RE: Ansible playbook for config generation

     
    Posted 03-04-2022 12:34
    Hi, 

    First off, the playbook that you pasted and have executed, looks to match exactly what you are seeing in the output.  The playbook doesn't do anything really as far as I can see.

    e.g. for all hosts don't gather facts, run a task that sets a fact called dest_dir to a value of "~/complete_config/". 

    So, based on that and the output produced when Ansible executes matches what you would expect to see.  

    I would suggest looking for other playbooks, and perhaps one that is make a reference to including a role.   I'd probably start by taking a look at the example-core-playbook.yaml and see what that is doing. 

    Regards,
    Andy

    ------------------------------
    Andy Sharp
    ------------------------------