diff --git a/README.rst b/README.rst index acd8ddd..6ae9cd0 100644 --- a/README.rst +++ b/README.rst @@ -29,10 +29,17 @@ _________ Functions _________ -* **print_result** - formats nicely and prints results on stdout -* **print_title** - formats nicely a title and prints it on stdout +* **print_result** - Formats nicely and prints results on stdout. +* **print_title** - Formats nicely a title and prints it on stdout. Processors __________ -* **PrintResult** - formats nicely and prints results on stdoud as soon as they are made available +* **PrintResult** - Formats nicely and prints results on stdout as soon as they are made available. + +Data +__________ + +* **echo_data** - Dummy task that echoes the data passed to it. +* **load_json** - Load a JSON file. +* **load_yaml** - Load a YAML file. diff --git a/docs/doctrees/api/functions.doctree b/docs/doctrees/api/functions.doctree index fd014f3..bd731f1 100644 Binary files a/docs/doctrees/api/functions.doctree and b/docs/doctrees/api/functions.doctree differ diff --git a/docs/doctrees/api/index.doctree b/docs/doctrees/api/index.doctree index 32d36fd..1dabb69 100644 Binary files a/docs/doctrees/api/index.doctree and b/docs/doctrees/api/index.doctree differ diff --git a/docs/doctrees/api/inventory.doctree b/docs/doctrees/api/inventory.doctree index 7025a12..d7605b7 100644 Binary files a/docs/doctrees/api/inventory.doctree and b/docs/doctrees/api/inventory.doctree differ diff --git a/docs/doctrees/api/processors.doctree b/docs/doctrees/api/processors.doctree index 451b5b1..2c119a3 100644 Binary files a/docs/doctrees/api/processors.doctree and b/docs/doctrees/api/processors.doctree differ diff --git a/docs/doctrees/api/tasks.doctree b/docs/doctrees/api/tasks.doctree new file mode 100644 index 0000000..964956c Binary files /dev/null and b/docs/doctrees/api/tasks.doctree differ diff --git a/docs/doctrees/environment.pickle b/docs/doctrees/environment.pickle index e758165..62b866f 100644 Binary files a/docs/doctrees/environment.pickle and b/docs/doctrees/environment.pickle differ diff --git a/docs/doctrees/index.doctree b/docs/doctrees/index.doctree index 4ba67d3..2cb7269 100644 Binary files a/docs/doctrees/index.doctree and b/docs/doctrees/index.doctree differ diff --git a/docs/doctrees/nbsphinx/tutorials/echo_data.ipynb b/docs/doctrees/nbsphinx/tutorials/echo_data.ipynb new file mode 100644 index 0000000..6526c8a --- /dev/null +++ b/docs/doctrees/nbsphinx/tutorials/echo_data.ipynb @@ -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 +} diff --git a/docs/doctrees/nbsphinx/tutorials/function_print_result.ipynb b/docs/doctrees/nbsphinx/tutorials/function_print_result.ipynb index 57cac67..e284ae5 100644 --- a/docs/doctrees/nbsphinx/tutorials/function_print_result.ipynb +++ b/docs/doctrees/nbsphinx/tutorials/function_print_result.ipynb @@ -22,7 +22,7 @@ "\n", "nr = InitNornir(\n", " inventory={\n", - " \"plugin\":\"SimpleInventory\",\n", + " \"plugin\":\"YAMLInventory\",\n", " \"options\": {\n", " \"host_file\": \"data/hosts.yaml\",\n", " \"group_file\": \"data/groups.yaml\",\n", diff --git a/docs/doctrees/nbsphinx/tutorials/inventory_SimpleInventory.ipynb b/docs/doctrees/nbsphinx/tutorials/inventory_YAMLInventory.ipynb similarity index 97% rename from docs/doctrees/nbsphinx/tutorials/inventory_SimpleInventory.ipynb rename to docs/doctrees/nbsphinx/tutorials/inventory_YAMLInventory.ipynb index b5398ca..5a2e96c 100644 --- a/docs/doctrees/nbsphinx/tutorials/inventory_SimpleInventory.ipynb +++ b/docs/doctrees/nbsphinx/tutorials/inventory_YAMLInventory.ipynb @@ -4,10 +4,10 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# inventory: SimpleInventory\n", + "# inventory: YAMLInventory\n", "\n", "\n", - "[SimpleInventory](../api/inventory.rst#nornir_utils.plugins.inventory.SimpleInventory) is an inventory plugin that builds the inventory from a few YAML files.\n", + "[YAMLInventory](../api/inventory.rst#nornir_utils.plugins.inventory.YAMLInventory) is an inventory plugin that builds the inventory from a few YAML files.\n", "\n", "## Data\n", "\n", @@ -203,7 +203,7 @@ "source": [ "## Example\n", "\n", - "Once you have the yaml files, using the plugin is very simple, you just need to specify the plugin you want to use is `SimpleInventory` and where to find the files:" + "Once you have the yaml files, using the plugin is very simple, you just need to specify the plugin you want to use is `YAMLInventory` and where to find the files:" ] }, { @@ -216,7 +216,7 @@ "\n", "nr = InitNornir(\n", " inventory={\n", - " \"plugin\":\"SimpleInventory\",\n", + " \"plugin\":\"YAMLInventory\",\n", " \"options\": {\n", " \"host_file\": \"data/hosts.yaml\",\n", " \"group_file\": \"data/groups.yaml\",\n", diff --git a/docs/doctrees/nbsphinx/tutorials/load_json.ipynb b/docs/doctrees/nbsphinx/tutorials/load_json.ipynb new file mode 100644 index 0000000..fadb9d6 --- /dev/null +++ b/docs/doctrees/nbsphinx/tutorials/load_json.ipynb @@ -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 +} diff --git a/docs/doctrees/nbsphinx/tutorials/load_yaml.ipynb b/docs/doctrees/nbsphinx/tutorials/load_yaml.ipynb new file mode 100644 index 0000000..e03a1bb --- /dev/null +++ b/docs/doctrees/nbsphinx/tutorials/load_yaml.ipynb @@ -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 +} diff --git a/docs/doctrees/nbsphinx/tutorials/processor_PrintResult.ipynb b/docs/doctrees/nbsphinx/tutorials/processor_PrintResult.ipynb index f894080..a41e877 100644 --- a/docs/doctrees/nbsphinx/tutorials/processor_PrintResult.ipynb +++ b/docs/doctrees/nbsphinx/tutorials/processor_PrintResult.ipynb @@ -50,7 +50,7 @@ "\n", "nr = InitNornir(\n", " inventory={\n", - " \"plugin\":\"SimpleInventory\",\n", + " \"plugin\":\"YAMLInventory\",\n", " \"options\": {\n", " \"host_file\": \"data/hosts.yaml\",\n", " \"group_file\": \"data/groups.yaml\",\n", diff --git a/docs/doctrees/tutorials/echo_data.doctree b/docs/doctrees/tutorials/echo_data.doctree new file mode 100644 index 0000000..18f82f5 Binary files /dev/null and b/docs/doctrees/tutorials/echo_data.doctree differ diff --git a/docs/doctrees/tutorials/function_print_result.doctree b/docs/doctrees/tutorials/function_print_result.doctree index 75e667b..1c336e6 100644 Binary files a/docs/doctrees/tutorials/function_print_result.doctree and b/docs/doctrees/tutorials/function_print_result.doctree differ diff --git a/docs/doctrees/tutorials/function_print_title.doctree b/docs/doctrees/tutorials/function_print_title.doctree index 90640e0..0eb80db 100644 Binary files a/docs/doctrees/tutorials/function_print_title.doctree and b/docs/doctrees/tutorials/function_print_title.doctree differ diff --git a/docs/doctrees/tutorials/index.doctree b/docs/doctrees/tutorials/index.doctree index a0da716..3888fdc 100644 Binary files a/docs/doctrees/tutorials/index.doctree and b/docs/doctrees/tutorials/index.doctree differ diff --git a/docs/doctrees/tutorials/inventory_SimpleInventory.doctree b/docs/doctrees/tutorials/inventory_YAMLInventory.doctree similarity index 91% rename from docs/doctrees/tutorials/inventory_SimpleInventory.doctree rename to docs/doctrees/tutorials/inventory_YAMLInventory.doctree index e5261a8..630f070 100644 Binary files a/docs/doctrees/tutorials/inventory_SimpleInventory.doctree and b/docs/doctrees/tutorials/inventory_YAMLInventory.doctree differ diff --git a/docs/doctrees/tutorials/load_json.doctree b/docs/doctrees/tutorials/load_json.doctree new file mode 100644 index 0000000..51e86b6 Binary files /dev/null and b/docs/doctrees/tutorials/load_json.doctree differ diff --git a/docs/doctrees/tutorials/load_yaml.doctree b/docs/doctrees/tutorials/load_yaml.doctree new file mode 100644 index 0000000..ec7db35 Binary files /dev/null and b/docs/doctrees/tutorials/load_yaml.doctree differ diff --git a/docs/doctrees/tutorials/processor_PrintResult.doctree b/docs/doctrees/tutorials/processor_PrintResult.doctree index ce40e5c..cab9f18 100644 Binary files a/docs/doctrees/tutorials/processor_PrintResult.doctree and b/docs/doctrees/tutorials/processor_PrintResult.doctree differ diff --git a/docs/html/_sources/api/tasks.rst.txt b/docs/html/_sources/api/tasks.rst.txt new file mode 100644 index 0000000..d0152ca --- /dev/null +++ b/docs/html/_sources/api/tasks.rst.txt @@ -0,0 +1,6 @@ +tasks +===== + +.. automodule:: nornir_utils.plugins.tasks.data + :members: + :undoc-members: diff --git a/docs/html/_sources/tutorials/echo_data.ipynb.txt b/docs/html/_sources/tutorials/echo_data.ipynb.txt new file mode 100644 index 0000000..0129dd7 --- /dev/null +++ b/docs/html/_sources/tutorials/echo_data.ipynb.txt @@ -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 +} diff --git a/docs/html/_sources/tutorials/function_print_result.ipynb.txt b/docs/html/_sources/tutorials/function_print_result.ipynb.txt index 57cac67..e284ae5 100644 --- a/docs/html/_sources/tutorials/function_print_result.ipynb.txt +++ b/docs/html/_sources/tutorials/function_print_result.ipynb.txt @@ -22,7 +22,7 @@ "\n", "nr = InitNornir(\n", " inventory={\n", - " \"plugin\":\"SimpleInventory\",\n", + " \"plugin\":\"YAMLInventory\",\n", " \"options\": {\n", " \"host_file\": \"data/hosts.yaml\",\n", " \"group_file\": \"data/groups.yaml\",\n", diff --git a/docs/html/tutorials/inventory_SimpleInventory.ipynb b/docs/html/_sources/tutorials/inventory_YAMLInventory.ipynb.txt similarity index 97% rename from docs/html/tutorials/inventory_SimpleInventory.ipynb rename to docs/html/_sources/tutorials/inventory_YAMLInventory.ipynb.txt index b5398ca..5a2e96c 100644 --- a/docs/html/tutorials/inventory_SimpleInventory.ipynb +++ b/docs/html/_sources/tutorials/inventory_YAMLInventory.ipynb.txt @@ -4,10 +4,10 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# inventory: SimpleInventory\n", + "# inventory: YAMLInventory\n", "\n", "\n", - "[SimpleInventory](../api/inventory.rst#nornir_utils.plugins.inventory.SimpleInventory) is an inventory plugin that builds the inventory from a few YAML files.\n", + "[YAMLInventory](../api/inventory.rst#nornir_utils.plugins.inventory.YAMLInventory) is an inventory plugin that builds the inventory from a few YAML files.\n", "\n", "## Data\n", "\n", @@ -203,7 +203,7 @@ "source": [ "## Example\n", "\n", - "Once you have the yaml files, using the plugin is very simple, you just need to specify the plugin you want to use is `SimpleInventory` and where to find the files:" + "Once you have the yaml files, using the plugin is very simple, you just need to specify the plugin you want to use is `YAMLInventory` and where to find the files:" ] }, { @@ -216,7 +216,7 @@ "\n", "nr = InitNornir(\n", " inventory={\n", - " \"plugin\":\"SimpleInventory\",\n", + " \"plugin\":\"YAMLInventory\",\n", " \"options\": {\n", " \"host_file\": \"data/hosts.yaml\",\n", " \"group_file\": \"data/groups.yaml\",\n", diff --git a/docs/html/_sources/tutorials/load_json.ipynb.txt b/docs/html/_sources/tutorials/load_json.ipynb.txt new file mode 100644 index 0000000..fadb9d6 --- /dev/null +++ b/docs/html/_sources/tutorials/load_json.ipynb.txt @@ -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 +} diff --git a/docs/html/_sources/tutorials/load_yaml.ipynb.txt b/docs/html/_sources/tutorials/load_yaml.ipynb.txt new file mode 100644 index 0000000..d213592 --- /dev/null +++ b/docs/html/_sources/tutorials/load_yaml.ipynb.txt @@ -0,0 +1,100 @@ +{ + "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", + "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 +} diff --git a/docs/html/_sources/tutorials/processor_PrintResult.ipynb.txt b/docs/html/_sources/tutorials/processor_PrintResult.ipynb.txt index f894080..a41e877 100644 --- a/docs/html/_sources/tutorials/processor_PrintResult.ipynb.txt +++ b/docs/html/_sources/tutorials/processor_PrintResult.ipynb.txt @@ -50,7 +50,7 @@ "\n", "nr = InitNornir(\n", " inventory={\n", - " \"plugin\":\"SimpleInventory\",\n", + " \"plugin\":\"YAMLInventory\",\n", " \"options\": {\n", " \"host_file\": \"data/hosts.yaml\",\n", " \"group_file\": \"data/groups.yaml\",\n", diff --git a/docs/html/api/functions.html b/docs/html/api/functions.html index cf0b153..137f43a 100644 --- a/docs/html/api/functions.html +++ b/docs/html/api/functions.html @@ -87,6 +87,7 @@
  • functions
  • inventory
  • processors
  • +
  • tasks
  • Tutorials
  • diff --git a/docs/html/api/index.html b/docs/html/api/index.html index cbec3d6..9dc9438 100644 --- a/docs/html/api/index.html +++ b/docs/html/api/index.html @@ -87,6 +87,7 @@
  • functions
  • inventory
  • processors
  • +
  • tasks
  • Tutorials
  • @@ -186,6 +187,7 @@

    APIfunctions
  • inventory
  • processors
  • +
  • tasks
  • diff --git a/docs/html/api/inventory.html b/docs/html/api/inventory.html index 306a2fa..627b68e 100644 --- a/docs/html/api/inventory.html +++ b/docs/html/api/inventory.html @@ -87,6 +87,7 @@
  • functions
  • inventory
  • processors
  • +
  • tasks
  • Tutorials
  • @@ -183,11 +184,11 @@

    inventory

    -
    -class nornir_utils.plugins.inventory.SimpleInventory(host_file: str = 'hosts.yaml', group_file: str = 'groups.yaml', defaults_file: str = 'defaults.yaml')
    +
    +class nornir_utils.plugins.inventory.YAMLInventory(host_file: str = 'hosts.yaml', group_file: str = 'groups.yaml', defaults_file: str = 'defaults.yaml')
    -
    -load() → nornir.core.inventory.Inventory
    +
    +load() → nornir.core.inventory.Inventory
    diff --git a/docs/html/api/processors.html b/docs/html/api/processors.html index 6889cca..78a1910 100644 --- a/docs/html/api/processors.html +++ b/docs/html/api/processors.html @@ -36,7 +36,7 @@ - + @@ -87,6 +87,7 @@
  • functions
  • inventory
  • processors
  • +
  • tasks
  • Tutorials
  • @@ -203,7 +204,7 @@

    processors - + diff --git a/docs/html/api/tasks.html b/docs/html/api/tasks.html new file mode 100644 index 0000000..90a2267 --- /dev/null +++ b/docs/html/api/tasks.html @@ -0,0 +1,315 @@ + + + + + + + + + + + tasks — nornir_utils documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + +
    + + + + + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    +
    +
    +
    + + + +
    +

    tasks

    +
    +
    +nornir_utils.plugins.tasks.data.load_json(task: nornir.core.task.Task, file: str) → nornir.core.task.Result
    +

    Loads a json file.

    +
    +
    Parameters
    +

    file – path to the file containing the json file to load

    +
    +
    +

    Examples

    +

    Simple example with ordered_dict:

    +
    > nr.run(task=load_json,
    +         file="mydata.json")
    +
    +
    +

    file: path to the file containing the json file to load

    +
    +
    Returns
    +

      +
    • result (dict): dictionary with the contents of the file

    • +
    +

    +
    +
    Return type
    +

    Result object with the following attributes set

    +
    +
    +
    + +
    +
    +nornir_utils.plugins.tasks.data.load_yaml(task: nornir.core.task.Task, file: str) → nornir.core.task.Result
    +

    Loads a yaml file.

    +
    +
    Parameters
    +

    file – path to the file containing the yaml file to load

    +
    +
    +

    Examples

    +

    Simple example with ordered_dict:

    +
    > nr.run(task=load_yaml,
    +         file="mydata.yaml")
    +
    +
    +
    +
    Returns
    +

      +
    • result (dict): dictionary with the contents of the file

    • +
    +

    +
    +
    Return type
    +

    Result object with the following attributes set

    +
    +
    +
    + +
    +
    +nornir_utils.plugins.tasks.data.echo_data(task: nornir.core.task.Task, **kwargs: Any) → nornir.core.task.Result
    +

    Dummy task that echoes the data passed to it. Useful in grouped_tasks +to debug data passed to tasks.

    +
    +
    Parameters
    +

    **kwargs – Any <key,value> pair you want

    +
    +
    Returns
    +

      +
    • result (dict): **kwargs passed to the task

    • +
    +

    +
    +
    Return type
    +

    Result object with the following attributes set

    +
    +
    +
    + +
    + + +
    + +
    + + +
    +
    + +
    + +
    + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/html/genindex.html b/docs/html/genindex.html index 25f2797..61fc4ae 100644 --- a/docs/html/genindex.html +++ b/docs/html/genindex.html @@ -150,17 +150,32 @@

    Index

    - L + E + | L | M | N | P - | S + | Y
    +

    E

    + + +
    +

    L

    +
    @@ -175,6 +190,8 @@

    M

  • nornir_utils.plugins.functions
  • nornir_utils.plugins.inventory +
  • +
  • nornir_utils.plugins.tasks.data
  • @@ -190,13 +207,20 @@

    N

  • module
  • - - + @@ -216,10 +240,10 @@

    P

    -

    S

    +

    Y

    diff --git a/docs/html/index.html b/docs/html/index.html index bb1014a..6f434ae 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -188,20 +188,28 @@

    Plugins

    Inventory

      -
    • SimpleInventory - Create an inventory from yaml files

    • +
    • YAMLInventory - Create an inventory from yaml files

    Functions

    Processors

    +
    +
    +

    Data

    +

    Contents:

    @@ -210,12 +218,16 @@

    Processorsfunctions
  • inventory
  • processors
  • +
  • tasks
  • Tutorials
  • diff --git a/docs/html/objects.inv b/docs/html/objects.inv index d279c1c..6aaa0a3 100644 Binary files a/docs/html/objects.inv and b/docs/html/objects.inv differ diff --git a/docs/html/py-modindex.html b/docs/html/py-modindex.html index fe75fb9..64853ba 100644 --- a/docs/html/py-modindex.html +++ b/docs/html/py-modindex.html @@ -173,6 +173,11 @@

    Python Module Index

        nornir_utils.plugins.inventory + + +     + nornir_utils.plugins.tasks.data + diff --git a/docs/html/searchindex.js b/docs/html/searchindex.js index 61fe5df..0df5b6b 100644 --- a/docs/html/searchindex.js +++ b/docs/html/searchindex.js @@ -1 +1 @@ -Search.setIndex({docnames:["api/functions","api/index","api/inventory","api/processors","index","tutorials/function_print_result","tutorials/function_print_title","tutorials/index","tutorials/inventory_SimpleInventory","tutorials/processor_PrintResult"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":2,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":2,"sphinx.domains.rst":2,"sphinx.domains.std":1,nbsphinx:3,sphinx:56},filenames:["api/functions.rst","api/index.rst","api/inventory.rst","api/processors.rst","index.rst","tutorials/function_print_result.ipynb","tutorials/function_print_title.ipynb","tutorials/index.rst","tutorials/inventory_SimpleInventory.ipynb","tutorials/processor_PrintResult.ipynb"],objects:{"nornir_utils.plugins":{functions:[0,0,0,"-"],inventory:[2,0,0,"-"]},"nornir_utils.plugins.functions":{print_result:[0,1,1,""],print_title:[0,1,1,""]},"nornir_utils.plugins.inventory":{SimpleInventory:[2,2,1,""]},"nornir_utils.plugins.inventory.SimpleInventory":{load:[2,3,1,""]},"nornir_utils.plugins.processors":{PrintResult:[3,2,1,""]}},objnames:{"0":["py","module","Python module"],"1":["py","function","Python function"],"2":["py","class","Python class"],"3":["py","method","Python method"]},objtypes:{"0":"py:module","1":"py:function","2":"py:class","3":"py:method"},terms:{"class":[2,3],"default":[2,5,8,9],"function":[1,7,9],"import":[5,6,8,9],"int":[0,3],"long":9,"return":[5,9],"true":0,"var":[0,5],"while":9,For:[5,9],a_dict:8,a_false_var:8,a_list:8,a_password:8,a_str:8,a_us:8,a_var:8,about:[3,5,6],abov:[5,9],all:5,also:5,apach:8,api:4,asdasd:8,ask:[5,9],assum:0,asynchron:9,attribut:0,avail:[4,9],becaus:9,bink:5,blah:8,bool:0,build:8,can:[5,8],care:5,cat:8,chang:[5,9],clear:9,code:[5,9],collect:4,comes_from_default:8,comes_from_dev1:8,comes_from_dev4:8,comes_from_group_1:8,complet:9,complex_result:5,complex_task:[5,9],connection_opt:8,content:[1,4,7],core:[0,2,5],could:[5,9],creat:4,data:[7,9],debug:[5,9],def:[5,9],defaults_fil:[2,5,8,9],dev1:[5,8,9],dev2:[5,8,9],dev3:[5,8,9],dev4:[5,8,9],dev5:[5,8,9],dict:8,did:[5,9],differ:[5,8],discard:9,docker:8,don:5,done:9,dummi:8,dummy2:8,dummy2_from_host:8,dummy2_from_parent_group:8,dummy_from_default:8,dummy_from_host:8,dummy_from_parent_group:8,dummy_task:[5,9],easili:5,end:5,eos:8,equal:5,error:0,exampl:7,execut:3,explicitli:9,extra:8,fail:0,fals:[0,5,8,9],faster:9,fav_result:5,feedback:9,few:8,file:[4,8],find:8,first:8,follow:[5,9],food:5,format:4,from:[0,4,5,6,8,9],from_default:8,from_group1:8,from_group:8,from_host:8,from_parent_group:8,group:[2,5,8,9],group_1:[5,8,9],group_2:[5,8,9],group_3:8,group_fil:[2,5,8,9],have:8,hawaiian:5,helper:0,higher:[0,3],host:[2,5,8,9],host_fil:[2,5,8,9],hostnam:8,how:8,howev:9,imagin:5,includ:9,index:4,info:[5,9],inform:[3,5],initnornir:[5,8,9],instanc:[5,9],instead:9,intermedi:[5,9],inventori:[1,5,7,9],jar:5,juno:8,just:8,larg:5,let:8,level:[0,3,9],like:[8,9],linux:8,list:0,load:2,localhost:8,log:[5,9],look:8,lot:[5,9],made:[4,9],mock:8,modul:4,my_var:8,name:8,napalm:8,nbval_ignore_output:9,need:[8,9],nested_data:8,netmiko:8,never:9,nginx:8,nice:4,no_group:[5,8,9],none:[0,8],nornir:[0,2,4,5,8,9],nornir_util:[0,2,3,5,6,9],note:9,notic:9,now:5,nrp:9,object:0,onc:8,one:5,ones:5,onli:[0,3,5,9],only_default:8,only_defined_in_default:8,option:[5,8,9],order:9,other:9,page:4,paramet:[0,3],paramiko:8,parent:5,parent_group:8,particularli:[5,9],password:8,piec:5,pip:4,pizza:5,plai:8,platform:8,plugin:[0,2,3,5,6,8,9],port:8,possibl:9,previou:0,print:[0,3,4,6,7,8,9],print_result:[0,4,7,9],print_titl:[0,4,6],printresult:[3,4,7],process:9,processor:[1,7],purpos:5,qwe:8,result:[0,3,4,5,9],role:8,root:8,run:[5,9],screen:[3,9],script:5,search:4,see:[5,8],select:5,sever:[0,3,7],severity_level:[0,3,5,9],should:5,similarli:9,simpl:[4,8],simpleinventori:[2,4,5,7,9],site1:8,site2:8,site:8,skip:9,some:9,someht:6,someth:9,soon:[4,9],specif:7,specifi:[5,8],start:9,stdoud:4,stdout:4,str:[0,2],superior:5,sw_char:5,take:[5,8,9],task:[0,3,5,9],task_with_data:5,thei:4,thi:[0,3,5,9],thing:[5,9],those:9,titl:[0,4,6],tutori:4,type:0,use:8,useful:[5,9],usernam:8,using:8,veri:[5,8],verifi:8,vvvv:[5,9],vvvvvvvvvvvvvvvvvvvvvvvvvvvv:9,vvvvvvvvvvvvvvvvvvvvvvvvvvvvv:9,vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:9,vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:9,vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:5,vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:5,vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:5,want:[0,5,8,9],where:[8,9],which:[0,5],window:5,with_processor:9,work:8,www:8,www_server:8,yaml:[2,4,5,8,9],you:[0,5,8,9],your:5},titles:["functions","API","inventory","processors","nornir_utils","functions: print_result","functions: print_result","Tutorials","inventory: SimpleInventory","processor: PrintResult"],titleterms:{"function":[0,4,5,6],api:1,data:[5,8],exampl:8,indic:4,instal:4,inventori:[2,4,8],nornir_util:4,plugin:4,print:5,print_result:[5,6],printresult:9,processor:[3,4,9],sever:[5,9],simpleinventori:8,specif:5,tabl:4,tutori:7}}) \ No newline at end of file +Search.setIndex({docnames:["api/functions","api/index","api/inventory","api/processors","api/tasks","index","tutorials/echo_data","tutorials/function_print_result","tutorials/function_print_title","tutorials/index","tutorials/inventory_YAMLInventory","tutorials/load_json","tutorials/load_yaml","tutorials/processor_PrintResult"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":2,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":2,"sphinx.domains.rst":2,"sphinx.domains.std":1,nbsphinx:3,sphinx:56},filenames:["api/functions.rst","api/index.rst","api/inventory.rst","api/processors.rst","api/tasks.rst","index.rst","tutorials/echo_data.ipynb","tutorials/function_print_result.ipynb","tutorials/function_print_title.ipynb","tutorials/index.rst","tutorials/inventory_YAMLInventory.ipynb","tutorials/load_json.ipynb","tutorials/load_yaml.ipynb","tutorials/processor_PrintResult.ipynb"],objects:{"nornir_utils.plugins":{functions:[0,0,0,"-"],inventory:[2,0,0,"-"]},"nornir_utils.plugins.functions":{print_result:[0,1,1,""],print_title:[0,1,1,""]},"nornir_utils.plugins.inventory":{YAMLInventory:[2,2,1,""]},"nornir_utils.plugins.inventory.YAMLInventory":{load:[2,3,1,""]},"nornir_utils.plugins.processors":{PrintResult:[3,2,1,""]},"nornir_utils.plugins.tasks":{data:[4,0,0,"-"]},"nornir_utils.plugins.tasks.data":{echo_data:[4,1,1,""],load_json:[4,1,1,""],load_yaml:[4,1,1,""]}},objnames:{"0":["py","module","Python module"],"1":["py","function","Python function"],"2":["py","class","Python class"],"3":["py","method","Python method"]},objtypes:{"0":"py:module","1":"py:function","2":"py:class","3":"py:method"},terms:{"class":[2,3],"default":[2,7,10,13],"function":[1,6,9,13],"import":[6,7,8,10,11,12,13],"int":[0,3],"long":13,"return":[4,7,13],"true":0,"var":[0,7],"while":13,For:[7,13],Useful:4,a_dict:10,a_false_var:10,a_list:10,a_password:10,a_str:10,a_us:10,a_var:10,about:[3,7,8],abov:[7,13],all:7,also:7,ani:4,apach:10,api:5,asdasd:10,ask:[7,13],assum:0,asynchron:13,attribut:[0,4],avail:[5,13],becaus:13,bink:7,blah:10,bool:0,build:10,can:[7,10],care:7,cat:10,chang:[6,7,13],clear:13,code:[7,13],collect:5,comes_from_default:10,comes_from_dev1:10,comes_from_dev4:10,comes_from_group_1:10,complet:13,complex_result:7,complex_task:[7,13],connection_opt:10,contain:4,content:[1,4,5,9],core:[0,2,4,6,7],could:[7,13],creat:5,data:[4,6,9,11,12,13],debug:[4,6,7,13],def:[6,7,13],defaults_fil:[2,7,10,13],dev1:[6,7,10,11,12,13],dev2:[6,7,10,11,12,13],dev3:[6,7,10,11,12,13],dev4:[6,7,10,11,12,13],dev5:[6,7,10,11,12,13],dict:[4,10],dictionari:4,did:[7,13],differ:[7,10],discard:13,docker:10,don:7,done:13,dummi:[4,5,10],dummy2:10,dummy2_from_host:10,dummy2_from_parent_group:10,dummy_from_default:10,dummy_from_host:10,dummy_from_parent_group:10,dummy_task:[7,13],easili:7,echo:[4,5,6],echo_data:[4,5,9],end:[6,7],eos:10,equal:7,error:0,exampl:[4,9],execut:3,explicitli:13,extra:10,fail:0,fals:[0,6,7,10,13],faster:13,fav_result:7,feedback:13,few:10,file:[4,5,10,11,12],filter:6,find:10,first:10,follow:[4,7,13],food:7,format:5,from:[0,5,6,7,8,10,11,12,13],from_default:10,from_group1:10,from_group:10,from_host:10,from_parent_group:10,group:[2,6,7,10,11,12,13],group_1:[6,7,10,11,12,13],group_2:[6,7,10,11,12,13],group_3:10,group_fil:[2,6,7,10,11,12,13],grouped_task:[4,6],have:10,hawaiian:7,helper:0,higher:[0,3],host:[2,6,7,10,11,12,13],host_fil:[2,6,7,10,11,12,13],hostnam:10,how:10,howev:13,imagin:7,includ:13,index:5,info:[6,7,13],inform:[3,7],initnornir:[6,7,10,11,12,13],instanc:[7,13],instead:13,intermedi:[7,13],inventori:[1,6,7,9,11,12,13],ip_address:[11,12],item:[11,12],jar:7,json:[4,5,11],juno:10,just:10,kei:4,kwarg:4,larg:7,let:10,level:[0,3,13],like:[10,13],linux:10,list:0,load:[2,4,5,11,12],load_json:[4,5,9],load_yaml:[4,5,9],localhost:10,log:[7,13],look:10,lot:[7,13],m_result:[11,12],made:[5,13],mock:10,modul:5,my_var:10,mydata:4,name:[6,10],napalm:10,nbval_ignore_output:13,need:[10,13],nested_data:10,netmiko:10,never:13,nginx:10,nice:5,no_group:[6,7,10,11,12,13],none:[0,10],nornir:[0,2,4,5,6,7,10,11,12,13],nornir_util:[0,2,3,4,6,7,8,11,12,13],note:13,notic:13,now:7,nrp:13,object:[0,4],onc:10,one:7,ones:7,onli:[0,3,7,13],only_default:10,only_defined_in_default:10,option:[6,7,10,11,12,13],order:13,ordered_dict:4,other:13,page:5,pair:4,paramet:[0,3,4],paramiko:10,parent:7,parent_group:10,particularli:[7,13],pass:[4,5,6],password:10,path:4,piec:7,pip:5,pizza:7,plai:10,platform:10,plugin:[0,2,3,4,6,7,8,10,11,12,13],port:10,possibl:13,previou:0,print:[0,3,5,8,9,10,11,12,13],print_result:[0,5,6,9,13],print_titl:[0,5,8],printresult:[3,5,9],process:13,processor:[1,9],purpos:7,qwe:10,result:[0,3,4,5,7,11,12,13],role:[6,10],root:10,run:[4,6,7,11,12,13],screen:[3,13],script:7,search:5,see:[7,10],select:7,set:4,sever:[0,3,9],severity_level:[0,3,7,13],should:7,similarli:13,simpl:[4,5,10],simpleinventori:[6,11,12],site1:10,site2:10,site:10,skip:13,some:13,someht:8,someth:13,soon:[5,13],specif:9,specifi:[7,10],start:13,stdout:5,str:[0,2,4],superior:7,sw_char:7,take:[7,10,13],task:[0,1,3,5,6,7,11,12,13],task_with_data:7,thei:5,thi:[0,3,7,13],thing:[7,13],those:13,titl:[0,5,8],tutori:5,type:[0,4],use:10,useful:[6,7,13],usernam:10,using:10,valu:4,veri:[7,10],verifi:10,vvvv:[6,7,13],vvvvvvvvvvvvvvvvvvvvvvvvvvvv:13,vvvvvvvvvvvvvvvvvvvvvvvvvvvvv:13,vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:13,vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:13,vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:7,vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:[6,7],vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:7,want:[0,4,7,10,13],where:[10,13],which:[0,7],window:7,with_processor:13,work:10,www:[6,10],www_server:10,yaml:[2,4,5,6,7,10,11,12,13],yamlinventori:[2,5,7,9,13],you:[0,4,7,10,13],your:7},titles:["functions","API","inventory","processors","tasks","nornir_utils","echo_data","functions: print_result","functions: print_result","Tutorials","inventory: YAMLInventory","load_json","load_yaml","processor: PrintResult"],titleterms:{"function":[0,5,7,8],api:1,data:[5,7,10],echo_data:6,exampl:[6,10,11,12],indic:5,instal:5,inventori:[2,5,10],load_json:11,load_yaml:12,nornir_util:5,plugin:5,print:7,print_result:[7,8],printresult:13,processor:[3,5,13],sever:[7,13],specif:7,tabl:5,task:4,tutori:9,yamlinventori:10}}) \ No newline at end of file diff --git a/docs/html/tutorials/echo_data.html b/docs/html/tutorials/echo_data.html new file mode 100644 index 0000000..e57f913 --- /dev/null +++ b/docs/html/tutorials/echo_data.html @@ -0,0 +1,522 @@ + + + + + + + + + + + echo_data — nornir_utils documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + +
    + + + + + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    +
    +
    +
    + + + +
    +

    echo_data

    +

    echo_data is a data plugin that echoes the data passed into it. It is useful in grouped_tasks debugging.

    +
    +

    Example

    +
    +
    [7]:
    +
    +
    +
    +from nornir import InitNornir
    +from nornir.core.filter import F
    +from nornir_utils.plugins.tasks.data import echo_data
    +from nornir_utils.plugins.functions import print_result
    +
    +nr = InitNornir(
    +    inventory={
    +        "plugin": "SimpleInventory",
    +        "options": {"host_file": "data/hosts.yaml", "group_file": "data/groups.yaml"},
    +    }
    +)
    +nr = nr.filter(~F(name="dev5.no_group"))
    +
    +
    +def grouped_task(task):
    +    task.run(task=echo_data, name=task.host.name, role=task.host["role"])
    +
    +
    +r = nr.run(task=grouped_task)
    +print_result(r)
    +
    +
    +
    +
    +
    +
    +
    +
    +grouped_task********************************************************************
    +* dev1.group_1 ** changed : False **********************************************
    +vvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
    +---- dev1.group_1 ** changed : False ------------------------------------------- INFO
    +{'role': 'www'}
    +^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    +* dev2.group_1 ** changed : False **********************************************
    +vvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
    +---- dev2.group_1 ** changed : False ------------------------------------------- INFO
    +{'role': 'db'}
    +^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    +* dev3.group_2 ** changed : False **********************************************
    +vvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
    +---- dev3.group_2 ** changed : False ------------------------------------------- INFO
    +{'role': 'www'}
    +^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    +* dev4.group_2 ** changed : False **********************************************
    +vvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
    +---- dev4.group_2 ** changed : False ------------------------------------------- INFO
    +{'role': 'db'}
    +^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    +
    +
    +
    +
    +
    + + +
    + +
    + + +
    +
    + +
    + +
    + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/html/tutorials/echo_data.ipynb b/docs/html/tutorials/echo_data.ipynb new file mode 100644 index 0000000..6526c8a --- /dev/null +++ b/docs/html/tutorials/echo_data.ipynb @@ -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 +} diff --git a/docs/html/tutorials/function_print_result.html b/docs/html/tutorials/function_print_result.html index c7e888c..d9e670c 100644 --- a/docs/html/tutorials/function_print_result.html +++ b/docs/html/tutorials/function_print_result.html @@ -37,7 +37,7 @@ - + @@ -85,13 +85,16 @@
    diff --git a/docs/html/tutorials/function_print_result.ipynb b/docs/html/tutorials/function_print_result.ipynb index 57cac67..e284ae5 100644 --- a/docs/html/tutorials/function_print_result.ipynb +++ b/docs/html/tutorials/function_print_result.ipynb @@ -22,7 +22,7 @@ "\n", "nr = InitNornir(\n", " inventory={\n", - " \"plugin\":\"SimpleInventory\",\n", + " \"plugin\":\"YAMLInventory\",\n", " \"options\": {\n", " \"host_file\": \"data/hosts.yaml\",\n", " \"group_file\": \"data/groups.yaml\",\n", diff --git a/docs/html/tutorials/function_print_title.html b/docs/html/tutorials/function_print_title.html index 6c54a7c..b2ace6c 100644 --- a/docs/html/tutorials/function_print_title.html +++ b/docs/html/tutorials/function_print_title.html @@ -36,7 +36,7 @@ - + @@ -85,9 +85,12 @@
    diff --git a/docs/html/tutorials/inventory_SimpleInventory.html b/docs/html/tutorials/inventory_YAMLInventory.html similarity index 94% rename from docs/html/tutorials/inventory_SimpleInventory.html rename to docs/html/tutorials/inventory_YAMLInventory.html index 08132cf..cb49643 100644 --- a/docs/html/tutorials/inventory_SimpleInventory.html +++ b/docs/html/tutorials/inventory_YAMLInventory.html @@ -8,7 +8,7 @@ - inventory: SimpleInventory — nornir_utils documentation + inventory: YAMLInventory — nornir_utils documentation @@ -36,7 +36,7 @@ - + @@ -85,13 +85,16 @@