Search This Blog

Thursday 14 January 2021

Use Environment variables in Python script

 This avoids using clear text user/pass in the code. While the user/pass are not encrypted they are stored on the local device where the script is running on.

Edit the bashrc file and add the key value pairs; location doesn't matter:

nano ~/.bashrc

export NORNIR_USERNAME="cisco"

export NORNIR_PASSWORD="cisco"

To use these variable in the python code (nornir 2.5) add the following:

nr.inventory.default.username = os.environ["NORNIR_USERNAME"]

nr.inventory.default.password = os.environ["NORNIR_PASSWORD"]

 That's it!

No comments:

Post a Comment

Nornir Compliance Check