Skip to content
This repository has been archived by the owner on Oct 12, 2020. It is now read-only.

11. flexible targeting system

Khelil Sator edited this page Jun 29, 2017 · 3 revisions
# salt ex4200-7 test.ping
ex4200-7:
    True

list:

# salt -L "ex4200-7, vqfx01" test.ping
vqfx01:
    True
ex4200-7:
    True

regex:

# salt "ex*" test.ping
ex4200-7:
    True
# salt "*" test.ping
vqfx01:
    True
ex4200-7:
    True
minion_1:
    True
vsrx01:
    Minion did not return. [Not connected]

nodegroups:

define nodegroups:

# more /etc/salt/master 
...
nodegroups: 
 group1: 'L@ex4200-7,vqfx01'
 group2: 
  - minion_1
  - ex4200-7
 group3: 'G@os_family:junos or minion_1'
...

Use one of the nodegroups to identify a list of targets:

# salt -N group1 test.ping
vqfx01:
    True
ex4200-7:
    True
# salt -N group2 test.ping
ex4200-7:
    True
minion_1:
    True
# salt -N group3 test.ping
vqfx01:
    True
ex4200-7:
    True
minion_1:
    True
vsrx01:
    Minion did not return. [Not connected]

grains:

junos facts:

# salt ex4200-7 junos.facts
ex4200-7:
    ----------
    facts:
        ----------
        2RE:
            False
        HOME:
            /var/home/remote
        RE0:
            ----------
            last_reboot_reason:
                0x2:watchdog
            mastership_state:
                master
            model:
                EX4200-48T, 8 POE
            status:
                OK
            up_time:
                281 days, 46 minutes, 58 seconds
        RE1:
            None
        RE_hw_mi:
            False
        current_re:
            - master
            - node
            - fwdd
            - member
            - pfem
            - fpc0
            - feb0
            - fpc16
        domain:
            poc-nl.jnpr.net
        fqdn:
            sac.poc-nl.jnpr.net
        hostname:
            sac
        hostname_info:
            ----------
            fpc0:
                sac
        ifd_style:
            SWITCH
        junos_info:
            ----------
            fpc0:
                ----------
                object:
                    ----------
                    build:
                        2
                    major:
                        - 12
                        - 3
                    minor:
                        11
                    type:
                        R
                text:
                    12.3R11.2
        master:
            RE0
        model:
            EX4200-48T
        model_info:
            ----------
            fpc0:
                EX4200-48T
        personality:
            SWITCH
        re_info:
            ----------
            default:
                ----------
                0:
                    ----------
                    last_reboot_reason:
                        0x2:watchdog
                    mastership_state:
                        master
                    model:
                        EX4200-48T, 8 POE
                    status:
                        OK
                default:
                    ----------
                    last_reboot_reason:
                        0x2:watchdog
                    mastership_state:
                        master
                    model:
                        EX4200-48T, 8 POE
                    status:
                        OK
        re_master:
            ----------
            default:
                0
        serialnumber:
            BP0208111225
        srx_cluster:
            None
        srx_cluster_id:
            None
        srx_cluster_redundancy_group:
            None
        switch_style:
            VLAN
        vc_capable:
            True
        vc_fabric:
            False
        vc_master:
            0
        vc_mode:
            Mixed
        version:
            12.3R11.2
        version_RE0:
            None
        version_RE1:
            None
        version_info:
            ----------
            build:
                2
            major:
                - 12
                - 3
            minor:
                11
            type:
                R
        virtual:
            False
    out:
        True

Junos facts are stored in grains:

# salt ex4200-7 grains.items
ex4200-7:
    ----------
    cpuarch:
        x86_64
    dns:
        ----------
        domain:
        ip4_nameservers:
            - 127.0.1.1
        ip6_nameservers:
        nameservers:
            - 127.0.1.1
        options:
        search:
        sortlist:
    gpus:
    hwaddr_interfaces:
        ----------
        ens33:
            00:0c:29:11:2e:cd
        lo:
            00:00:00:00:00:00
    id:
        ex4200-7
    junos_facts:
        ----------
        2RE:
            False
        HOME:
            /var/home/remote
        RE0:
            ----------
            last_reboot_reason:
                0x2:watchdog
            mastership_state:
                master
            model:
                EX4200-48T, 8 POE
            status:
                OK
            up_time:
                283 days, 21 hours, 12 minutes, 32 seconds
        RE1:
            None
        RE_hw_mi:
            False
        current_re:
            - master
            - node
            - fwdd
            - member
            - pfem
            - fpc0
            - feb0
            - fpc16
        domain:
            poc-nl.jnpr.net
        fqdn:
            sac.poc-nl.jnpr.net
        hostname:
            sac
        hostname_info:
            ----------
            fpc0:
                sac
        ifd_style:
            SWITCH
        junos_info:
            ----------
            fpc0:
                ----------
                object:
                    ----------
                    build:
                        2
                    major:
                        - 12
                        - 3
                    minor:
                        11
                    type:
                        R
                text:
                    12.3R11.2
        master:
            RE0
        model:
            EX4200-48T
        model_info:
            ----------
            fpc0:
                EX4200-48T
        personality:
            SWITCH
        re_info:
            ----------
            default:
                ----------
                0:
                    ----------
                    last_reboot_reason:
                        0x2:watchdog
                    mastership_state:
                        master
                    model:
                        EX4200-48T, 8 POE
                    status:
                        OK
                default:
                    ----------
                    last_reboot_reason:
                        0x2:watchdog
                    mastership_state:
                        master
                    model:
                        EX4200-48T, 8 POE
                    status:
                        OK
        re_master:
            ----------
            default:
                0
        serialnumber:
            BP0208111225
        srx_cluster:
            None
        srx_cluster_id:
            None
        srx_cluster_redundancy_group:
            None
        switch_style:
            VLAN
        vc_capable:
            True
        vc_fabric:
            False
        vc_master:
            0
        vc_mode:
            Mixed
        version:
            12.3R11.2
        version_RE0:
            None
        version_RE1:
            None
        version_info:
            ----------
            build:
                2
            major:
                - 12
                - 3
            minor:
                11
            type:
                R
        virtual:
            False
    kernel:
        unknown
    kernelrelease:
        proxy
    locale_info:
        ----------
    machine_id:
        98073913196c4a9e8c3911408ea59888
    master:
        192.168.233.17
    mem_total:
        0
    nodename:
        ksator-virtual-machine
    num_gpus:
        0
    os:
        proxy
    os_family:
        junos
    osarch:
        x86_64
    osfinger:
        proxy-proxy
    osfullname:
        proxy
    osrelease:
        proxy
    osrelease_info:
        - proxy
    path:
        /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
    ps:
        ps -efHww
    pythonexecutable:
        /usr/bin/python
    pythonpath:
        - /usr/local/bin
        - /usr/lib/python2.7
        - /usr/lib/python2.7/plat-x86_64-linux-gnu
        - /usr/lib/python2.7/lib-tk
        - /usr/lib/python2.7/lib-old
        - /usr/lib/python2.7/lib-dynload
        - /home/ksator/.local/lib/python2.7/site-packages
        - /usr/local/lib/python2.7/dist-packages
        - /usr/lib/python2.7/dist-packages
    pythonversion:
        - 2
        - 7
        - 12
        - final
        - 0
    saltpath:
        /usr/local/lib/python2.7/dist-packages/salt
    saltversion:
        2017.7.0-202-g3c8dee0
    saltversioninfo:
        - 2017
        - 7
        - 0
        - 0
    virtual:
        VMware
    zmqversion:
        4.1.6

use a grain value to identify targets:

# salt -G 'junos_facts:model:EX4200-48T' junos.cli "show version"
ex4200-7:
    ----------
    message:
        
        fpc0:
        --------------------------------------------------------------------------
        Hostname: sac
        Model: ex4200-48t
        JUNOS Base OS boot [12.3R11.2]
        JUNOS Base OS Software Suite [12.3R11.2]
        JUNOS Kernel Software Suite [12.3R11.2]
        JUNOS Crypto Software Suite [12.3R11.2]
        JUNOS Online Documentation [12.3R11.2]
        JUNOS Enterprise Software Suite [12.3R11.2]
        JUNOS Packet Forwarding Engine Enterprise Software Suite [12.3R11.2]
        JUNOS Routing Software Suite [12.3R11.2]
        JUNOS Web Management [12.3R11.2]
        JUNOS FIPS mode utilities [12.3R11.2]
    out:
        True
# salt -G 'os_family:junos' test.ping
ex4200-7:
    True
vqfx01:
    True
vsrx01:
    Minion did not return. [Not connected]