SaltStack code snippets
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images
scripts
README.md
account.py
check_account.py
cluster.py
cpuinfo.py
fsinfo.py
linux_bonding.py
linux_fiberchannel.py
memory.py
pacemaker.py
rpmlibpkg.py
rpmpkg.py
service_iana.py
swap.py

README.md

Codacy Badge License

SaltStack code snippets for Linux

A set of code snippets that can be used to build SaltStack execution modules.

A Salt execution module is a Python or Cython module placed in a directory called _modules/ at the root of the Salt fileserver, usually /srv/salt.

The scripts folder contains Python sample scripts that make use of SaltStack as a backend.

account

  • account.get_group_list - Return the list of local groups
myserver:
    ----------
    root:
        ----------
        gid:
            0
    ...
    oinstall:
        ----------
        gid:
            501
        secgroups:
            - oracle
    ...
  • account.get_user_list - Return the list of local users
myserver:
    ----------
    bin:
        ----------
        gecos:
            bin
        gid:
            1
        homedir:
            /bin
        shell:
            /sbin/nologin
        uid:
            1
    ...
  • get_passwd_raw - Return the raw content of the file /etc/passwd
myserver:
    - root:x:0:0:root:/root:/bin/bash
    - bin:x:1:1:bin:/bin:/sbin/nologin
    - daemon:x:2:2:daemon:/sbin:/sbin/nologin
    ...

cpuinfo

  • cpuinfo.proc - Return the number of core, logical, and CPU sockets
myserver:
    ----------
    cores:
        10
    logicals:
        40
    sockets:
        2

fsinfo

  • fsinfo.usage - Return some informations about the configured file systems
myserver:
    ----------
    /:
        ----------
        autofs:
            false
        automount:
            true
        available:
            1.8GB
        device:
            /dev/mapper/rootvg-rootlv
        fstype:
            ext4
        lvm-pvdevice:
            /dev/mapper/mpatha2
        lvm-vgname:
            rootvg
        mountpoint:
            /
        scope:
            Unknown
        size:
            1.9GB
    /sharednfs:
        ----------
        autofs:
            false
        automount:
            true
        available:
            477.1GB
        device:
            nas.domain.eu:/PARTNFS/sharedfolder
        fstype:
            nfs
        mountpoint:
            /sharednfs
        size:
            2.0TB
        used:
            1.5TB
    ...

linux_bonding

  • linux_bonding.device_list - Return the list of the bonding device
myserver:
    ----------
    - bond0
  • linux_bonding.topology - Return the topology of the network bonding
myserver:
    ----------
    bond0:
        ----------
        bonding_mode:
            fault-tolerance (active-backup)
        currently_active_slave:
            em1
        down_delay_(ms):
            100
        em1:
            ----------
            duplex:
                full
            link_failure_count:
                0
            mii_status:
                up
            permanent_hw_addr:
                28:f1:0e:70:23:6e
            slave_queue_id:
                0
            speed:
                10000 Mbps
        em2:
            ----------
            duplex:
                full
            link_failure_count:
                0
            mii_status:
                up
            permanent_hw_addr:
                28:f1:0e:70:23:71
            slave_queue_id:
                0
            speed:
                10000 Mbps
        ethernet_channel_bonding_driver:
            v3.7.1 (April 27, 2011)
        mii_polling_interval_(ms):
            100
        mii_status:
            up
        primary_slave:
            None
        slave_interfaces:
            - em1
            - em2
        up_delay_(ms):
            0

linux_fiberchannel

  • linux_fiberchannel.show - View system fiber channel device information
myserver:
    host11:
        ----------
        Class:
            fc_host
        Class Device:
            host11
        Class Device path:
            /sys/devices/virtual/net/em1.550/ctlr_0/host11/fc_host/host11
        Device:
            host11
        Device path:
            /sys/devices/virtual/net/em1.550/ctlr_0/host11
        active_fc4s:
            0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
        dev_loss_tmo:
            60
        fabric_name:
            0x2226000573d92e21
        issue_lip:
            <store method only>
        max_npiv_vports:
            65535
        maxframe_size:
            2048 bytes
        node_name:
            0x200028f10e702370
        npiv_vports_inuse:
            0
        port_id:
            0x6a0801
        port_name:
            0x200128f10e702370
        port_state:
            Online
        port_type:
            NPort (fabric via point-to-point)
        speed:
            10 Gbit
        supported_classes:
            Class 3
        supported_fc4s:
            0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
        supported_speeds:
            1 Gbit, 10 Gbit
        symbolic_name:
            bnx2fc (QLogic BCM57810) v2.10.3 over em1.550
        tgtid_bind_type:
            wwpn (World Wide Port Name)
        uevent:
            DEVTYPE=scsi_host
        vport_create:
            <store method only>
        vport_delete:
            <store method only>
    host12:
        ----------
        ...

memory

  • memory.usage - Return some informations on physical memory and swap
myserver:
    ----------
    MemAvailable:
         15 GB
    MemFree:
         11 GB
    MemTotal:
         15 GB
    SwapFree:
          2 GB
    SwapTotal:
          2 GB

pacemaker

  • cluster_local_node
  • cluster_local_node_status
  • cluster_name
  • cluster_nodes
  • cluster_nodes_status
  • cluster_resource_group_list
  • cluster_resources
  • cluster_service_status
  • cluster_stonith_configured
  • is_cluster_member

rpmpkg, rpmlibpkg

  • rpmpkg.buildtime - Return the build date and time
myserver:
    Fri Jan 27 23:18:03 2017
  • rpmpkg.lastupdate - Return the date of the last rpm package update/installation
myserver:
    Fri Feb  3 12:38:13 2017
  • rpmpkg.list_pkgs - List the packages currently installed in a dict
myserver:
    ----------
    GeoIP:
        1.5.0-11.el7.x86_64
    NetworkManager:
        1:1.4.0-13.el7_3.x86_64
    NetworkManager-config-server:
        1:1.4.0-13.el7_3.x86_64
    ...
 
    zip:
        3.0-11.el7.x86_64
    zlib:
        1.2.7-17.el7.x86_64

service_iana

  • get_service_list - Return a dictionary of services recorded in /etc/services
myserver:
    ----------
    1/ddp:
        ----------
        name:
            rtmp
        port:
            1
        protocol:
            ddp
    1/tcp:
        ----------
        name:
            tcpmux
        port:
            1
        protocol:
            tcp
    ...

swap

  • swap.usage - Return informations for swap filesystem
myserver:
    ----------
    /dev/mapper/rootvg-swaplv:
        ----------
        available:
            2.0GB
        device:
            /dev/dm-12
        priority:
            -1
        size:
            2.0GB
        used:
            0.0kB