-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the data-plugins into nornir_utils (#4)
- Loading branch information
Showing
66 changed files
with
3,413 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"source": [ | ||
"# echo_data\n", | ||
"\n", | ||
"echo_data is a data plugin that echoes the data passed into it. It is useful in grouped_tasks debugging.\n", | ||
"\n", | ||
"## Example" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": { | ||
"pycharm": { | ||
"name": "#%%\n" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\u001b[1m\u001b[36mgrouped_task********************************************************************\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[34m* dev1.group_1 ** changed : False **********************************************\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32mvvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32m---- dev1.group_1 ** changed : False ------------------------------------------- INFO\u001b[0m\n", | ||
"\u001b[0m{'role': 'www'}\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32m^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[34m* dev2.group_1 ** changed : False **********************************************\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32mvvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32m---- dev2.group_1 ** changed : False ------------------------------------------- INFO\u001b[0m\n", | ||
"\u001b[0m{'role': 'db'}\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32m^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[34m* dev3.group_2 ** changed : False **********************************************\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32mvvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32m---- dev3.group_2 ** changed : False ------------------------------------------- INFO\u001b[0m\n", | ||
"\u001b[0m{'role': 'www'}\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32m^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[34m* dev4.group_2 ** changed : False **********************************************\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32mvvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32m---- dev4.group_2 ** changed : False ------------------------------------------- INFO\u001b[0m\n", | ||
"\u001b[0m{'role': 'db'}\u001b[0m\n", | ||
"\u001b[0m\u001b[1m\u001b[32m^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", | ||
"\u001b[0m" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from nornir import InitNornir\n", | ||
"from nornir.core.filter import F\n", | ||
"from nornir_utils.plugins.tasks.data import echo_data\n", | ||
"from nornir_utils.plugins.functions import print_result\n", | ||
"\n", | ||
"nr = InitNornir(\n", | ||
" inventory={\n", | ||
" \"plugin\": \"SimpleInventory\",\n", | ||
" \"options\": {\"host_file\": \"data/hosts.yaml\", \"group_file\": \"data/groups.yaml\"},\n", | ||
" }\n", | ||
")\n", | ||
"nr = nr.filter(~F(name=\"dev5.no_group\"))\n", | ||
"\n", | ||
"\n", | ||
"def grouped_task(task):\n", | ||
" task.run(task=echo_data, name=task.host.name, role=task.host[\"role\"])\n", | ||
"\n", | ||
"\n", | ||
"r = nr.run(task=grouped_task)\n", | ||
"print_result(r)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"source": [ | ||
"# load_json\n", | ||
"\n", | ||
"Loads a JSON file.\n", | ||
"\n", | ||
"## Example" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": { | ||
"pycharm": { | ||
"name": "#%%\n" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n", | ||
"----------------------------------------\n", | ||
"Host: dev1.group_1\n", | ||
"JSON data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']\n", | ||
"----------------------------------------\n", | ||
"\n", | ||
"----------------------------------------\n", | ||
"Host: dev2.group_1\n", | ||
"JSON data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']\n", | ||
"----------------------------------------\n", | ||
"\n", | ||
"----------------------------------------\n", | ||
"Host: dev3.group_2\n", | ||
"JSON data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']\n", | ||
"----------------------------------------\n", | ||
"\n", | ||
"----------------------------------------\n", | ||
"Host: dev4.group_2\n", | ||
"JSON data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']\n", | ||
"----------------------------------------\n", | ||
"\n", | ||
"----------------------------------------\n", | ||
"Host: dev5.no_group\n", | ||
"JSON data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']\n", | ||
"----------------------------------------\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from nornir import InitNornir\n", | ||
"from nornir_utils.plugins.tasks.data import load_json\n", | ||
"\n", | ||
"nr = InitNornir(\n", | ||
" inventory={\n", | ||
" \"plugin\": \"SimpleInventory\",\n", | ||
" \"options\": {\"host_file\": \"data/hosts.yaml\", \"group_file\": \"data/groups.yaml\"},\n", | ||
" }\n", | ||
")\n", | ||
"\n", | ||
"r = nr.run(task=load_json, file=\"data/ip_addresses.json\")\n", | ||
"for host, m_result in r.items():\n", | ||
" print()\n", | ||
" print(\"-\" * 40)\n", | ||
" print(f\"Host: {host}\")\n", | ||
" print(f\"JSON data: {m_result.result}\")\n", | ||
" print(\"-\" * 40)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"source": [ | ||
"# load_yaml\n", | ||
"\n", | ||
"Loads a YAML file.\n", | ||
"\n", | ||
"## Example" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 20, | ||
"metadata": { | ||
"pycharm": { | ||
"name": "#%%\n" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n", | ||
"----------------------------------------\n", | ||
"Host: dev1.group_1\n", | ||
"YAML data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']\n", | ||
"----------------------------------------\n", | ||
"\n", | ||
"----------------------------------------\n", | ||
"Host: dev2.group_1\n", | ||
"YAML data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']\n", | ||
"----------------------------------------\n", | ||
"\n", | ||
"----------------------------------------\n", | ||
"Host: dev3.group_2\n", | ||
"YAML data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']\n", | ||
"----------------------------------------\n", | ||
"\n", | ||
"----------------------------------------\n", | ||
"Host: dev4.group_2\n", | ||
"YAML data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']\n", | ||
"----------------------------------------\n", | ||
"\n", | ||
"----------------------------------------\n", | ||
"Host: dev5.no_group\n", | ||
"YAML data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']\n", | ||
"----------------------------------------\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from nornir import InitNornir\n", | ||
"from nornir_utils.plugins.tasks.data import load_yaml\n", | ||
"\n", | ||
"nr = InitNornir(\n", | ||
" inventory={\n", | ||
" \"plugin\": \"SimpleInventory\",\n", | ||
" \"options\": {\"host_file\": \"data/hosts.yaml\", \"group_file\": \"data/groups.yaml\"},\n", | ||
" }\n", | ||
")\n", | ||
"\n", | ||
"r = nr.run(task=load_yaml, file=\"data/ip_addresses.yaml\")\n", | ||
"for host, m_result in r.items():\n", | ||
" print()\n", | ||
" print(\"-\" * 40)\n", | ||
" print(f\"Host: {host}\")\n", | ||
" print(f\"YAML data: {m_result.result}\")\n", | ||
" print(\"-\" * 40)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+44.5 KB
...torials/inventory_SimpleInventory.doctree → ...tutorials/inventory_YAMLInventory.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tasks | ||
===== | ||
|
||
.. automodule:: nornir_utils.plugins.tasks.data | ||
:members: | ||
:undoc-members: |
Oops, something went wrong.