napalm-automation / napalm-salt

Modules for event-driven network automation and orchestration using Salt
Apache License 2.0
127 stars 36 forks source link

Getting "State 'netconfig.managed' was not found" error when scheduling config enforcement #62

Closed tim-fiola closed 5 years ago

tim-fiola commented 5 years ago

Hello. I'm trying to enforce ntp peers and client configs on a napalm minion via periodic scheduling. It is saying that netconfig.managed is not found in vsrx.ntp. However, that statement does exist in vsrx.ntp

I am seeing this error in the log:

__schedule_return   {
    "_stamp": "2019-07-08T21:23:02.741697", 
    "cmd": "_return", 
    "fun": "state.sls", 
    "fun_args": [
        "vsrx.ntp"
    ], 
    "id": "ip-172-31-33-152.us-west-2.compute.internal_master", 
    "jid": "req", 
    "pid": 16518, 
    "return": {
        "data": {
            "ip-172-31-33-152.us-west-2.compute.internal_master": {
                "netconfig_|-ntp_config_example_|-ntp_config_example_|-managed": {
                    "__run_num__": 0, 
                    "changes": {}, 
                    "comment": "State 'netconfig.managed' was not found in SLS 'vsrx.ntp'\nReason: 'netconfig' __virtual__ returned False: \"netconfig\"\" (/usr/lib/python2.7/dist-packages/salt/states/netconfig.pyc) cannot be loaded: NAPALM is not installed or not running in a (proxy) minion\n", 
                    "name": "ntp_config_example", 
                    "result": false
                }
            }
        }, 
        "outputter": "highstate", 
        "retcode": 1
    }, 
    "schedule": "ntp_config_master", 
    "success": true
}

Here is the relevant config in /etc/salt/master:

schedule:
  ntp_config_master:
    function: state.sls
    args:
      - vsrx.ntp
    seconds: 15

Here is /srv/states/vsrx/ntp.sls: Notice netconfig.managed is present -

ntp_config_example:
  netconfig.managed:
    - template_name: /srv/templates/ntp.jinja #salt://ntp.jinja could be used if accesing remotely
    - peers: {{ pillar.get('ntp.peers', []) | json }}
    - servers: {{ pillar.get('ntp.servers', []) | json }}

/srv/pillar/top.sls file:

ubuntu@ip-172-31-33-152:/srv/pillar$ cat top.sls 
# The tops.sls file specifies minions and the files that contain
# the details for each minion
# insert in /srv/pillars
base:
  'vSRX-4':
    - vSRX-4-details
    - ntp
  'rt4_minion_172.16.10.196':
    - request_tracker

This does work when I initiate via the CLI: sudo salt 'vSRX-4' state.sls vsrx.ntp

ubuntu@ip-172-31-33-152:~$  sudo salt 'vSRX-4' state.sls vsrx.ntp
vSRX-4:
----------
          ID: ntp_config_example
    Function: netconfig.managed
      Result: True
     Comment: Configuration changed!
     Started: 21:30:38.073698
    Duration: 8124.674 ms
     Changes:   
              ----------
              diff:
                  [edit system]
                  +   ntp {
                  +       peer 10.11.12.13;
                  +       peer 14.15.16.17;
                  +       server 1.2.3.4;
                  +       server 5.6.7.8;
                  +   }

Summary for vSRX-4
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time:   8.125 s
ubuntu@ip-172-31-33-152:~

SALT version is Nitrogen:

ubuntu@ip-172-31-33-152:~$ salt --version
salt 2017.7.0-854-gf61ccae (Nitrogen)
ubuntu@ip-172-31-33-152:~$ 
tim-fiola commented 5 years ago
Salt Version:
           Salt: 2017.7.0-854-gf61ccae

Dependency Versions:
           cffi: 1.11.5
       cherrypy: 3.5.0
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 17.0.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.6

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-1066-aws
         system: Linux
        version: Ubuntu 16.04 xenial
tim-fiola commented 5 years ago

vSRX-4 pillar file /srv/pillar/vSRX-4-details.sls

ubuntu@ip-172-31-33-152:/srv$ cat pillar/vSRX-4-details.sls 
# put in /srv/pillar
proxy:
  proxytype: napalm
  driver: junos
  host: 172.31.47.219
  user: ubuntu # salt user that will log into device
  passwd: '' # no password since we are using ssh keys
  optional_args:
    key_file: /home/ubuntu/tim-test.pem # ssh key file for device authentication 

/srv/pillar/ntp.sls file:

ubuntu@ip-172-31-33-152:/srv$ cat /srv/pillar/ntp.sls 
ntp.servers:
  - 1.2.3.4
  - 5.6.7.8
ntp.peers:
  - 10.11.12.13
  - 14.15.16.17
tim-fiola commented 5 years ago

I see my error now. It was attempting to apply this to the master, not all the minions, because I had this configured on the master config file. I understand how it works now.