{"id":161,"date":"2023-09-23T12:38:39","date_gmt":"2023-09-23T12:38:39","guid":{"rendered":"https:\/\/www.netasic.com\/?p=161"},"modified":"2026-05-18T15:34:34","modified_gmt":"2026-05-18T15:34:34","slug":"getting-started-with-network-automation-using-ansible","status":"publish","type":"post","link":"https:\/\/www.netasic.com\/index.php\/2023\/09\/23\/getting-started-with-network-automation-using-ansible\/","title":{"rendered":"Getting Started with Network Automation using Ansible"},"content":{"rendered":"<p>Ansible is an agentless automation tool, which allow dramatically reduce the time required for configuring our networks systems. We can automate many of our daily tasks and even dynamically manage of our configuration what we call orchestration.<\/p>\n<h3>Let&#8217;s start<\/h3>\n<ol>\n<li><a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/getting_started\/index.html\" target=\"_blank\" rel=\"noopener\">Getting started with Ansible<\/a><\/li>\n<li><a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/installation_guide\/index.html\" target=\"_blank\" rel=\"noopener\">Installation Guide<\/a><\/li>\n<\/ol>\n<h3>After installation ansible on Linux:<\/h3>\n<ol>\n<li>Finding <span style=\"color: #993300;\">ansible.cfg<\/span> file:<\/li>\n<\/ol>\n<pre><span style=\"color: #000080;\"><strong>ansible@virtualbox:~$ ansible --version<\/strong><\/span>\r\n<span style=\"color: #000080;\">ansible [core 2.14.5]<\/span>\r\n<span style=\"color: #993300;\">config file = \/home\/ansible\/ansible.cfg<\/span>\r\n<span style=\"color: #000080;\">configured module search path = ['\/home\/ansible\/.ansible\/plugins\/modules', '\/usr\/share\/ansible\/plugins\/modules']<\/span>\r\n<span style=\"color: #000080;\">ansible python module location = \/usr\/lib\/python3\/dist-packages\/ansible<\/span>\r\n<span style=\"color: #000080;\">ansible collection location = \/home\/ansible\/.ansible\/collections:\/usr\/share\/ansible\/collections<\/span>\r\n<span style=\"color: #000080;\">executable location = \/usr\/bin\/ansible<\/span>\r\n<span style=\"color: #000080;\">python version = 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (\/usr\/bin\/python3)<\/span>\r\n<span style=\"color: #000080;\">jinja version = 3.0.3<\/span>\r\n<span style=\"color: #000080;\">libyaml = True<\/span><\/pre>\n<p>2. Finding path to <span style=\"color: #993300;\">&#8220;inventory&#8221;:<\/span><\/p>\n<pre><span style=\"color: #000080;\"><strong>ansible@virtualbox:~$ cat \/home\/ansible\/ansible.cfg | grep 'inventory'<\/strong><\/span>\r\n<span style=\"color: #000080;\"># For some uses you can also look into custom vars_plugins to merge on input, even substituting the default ``host_group_vars`` that is in charge of parsing the ``host_vars\/`` and ``group_vars\/`` directories. Most users of this setting are only interested in inventory scope, but the setting itself affects all sources and makes debugging even harder.<\/span>\r\n<span style=\"color: #000080;\"># (pathlist) Comma separated list of Ansible inventory sources<\/span>\r\n<span style=\"color: #993300;\">;inventory=\/etc\/ansible\/hosts<\/span>\r\n<span style=\"color: #000080;\">;inventory_plugins={{ ANSIBLE_HOME ~ \"\/plugins\/inventory:\/usr\/share\/ansible\/plugins\/inventory\" }}<\/span><\/pre>\n<p>3. Adding addresses IP of nodes in &#8220;inventory&#8221; file:<\/p>\n<pre><span style=\"color: #000080;\"><strong>ansible@virtualbox:~$ cat \/etc\/ansible\/hosts<\/strong>\r\n# This is the default ansible 'hosts' file.\r\n#\r\n# It should live in \/etc\/ansible\/hosts\r\n#\r\n# - Comments begin with the '#' character\r\n# - Blank lines are ignored\r\n# - Groups of hosts are delimited by [header] elements\r\n# - You can enter hostnames or ip addresses\r\n# - A hostname\/ip can be a member of multiple groups\r\n\r\n# Ex 1: Ungrouped hosts, specify before any group headers:\r\n\r\n\r\n[all:vars]\r\nansible_ssh_pass=cisco\r\nansible_network_os=ios\r\nansible_connection=network_cli\r\n\r\n[test]\r\nlocalhost ansible_connection=local\r\n\r\n[router]\r\n10.0.0.1\r\n10.0.0.2\r\n10.0.0.10<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>4. Checking connection with nodes:<\/p>\n<pre><span style=\"color: #000080;\"><strong>ansible@virtualbox:~$ ansible all -m ping<\/strong><\/span>\r\n<span style=\"color: #008000;\">localhost | SUCCESS =&gt; {<\/span>\r\n<span style=\"color: #000080;\">\"ansible_facts\": {<\/span>\r\n<span style=\"color: #000080;\">\"discovered_interpreter_python\": \"\/usr\/bin\/python3\"<\/span>\r\n<span style=\"color: #000080;\">},<\/span>\r\n<span style=\"color: #000080;\">\"changed\": false,<\/span>\r\n<span style=\"color: #000080;\">\"ping\": \"pong\"<\/span>\r\n<span style=\"color: #000080;\">}<\/span>\r\n<span style=\"color: #000080;\">[WARNING]: ansible-pylibssh not installed, falling back to paramiko<\/span>\r\n<span style=\"color: #000080;\">[WARNING]: ansible-pylibssh not installed, falling back to paramiko<\/span>\r\n<span style=\"color: #000080;\">[WARNING]: ansible-pylibssh not installed, falling back to paramiko<\/span>\r\n<span style=\"color: #008000;\">10.0.0.2 | SUCCESS =&gt; {<\/span>\r\n<span style=\"color: #000080;\">\"changed\": false,<\/span>\r\n<span style=\"color: #000080;\">\"ping\": \"pong\"<\/span>\r\n<span style=\"color: #000080;\">}<\/span>\r\n<span style=\"color: #008000;\">10.0.0.1 | SUCCESS =&gt; {<\/span>\r\n<span style=\"color: #000080;\">\"changed\": false,<\/span>\r\n<span style=\"color: #000080;\">\"ping\": \"pong\"<\/span>\r\n<span style=\"color: #000080;\">}<\/span>\r\n<span style=\"color: #008000;\">10.0.0.10 | SUCCESS =&gt; {<\/span>\r\n<span style=\"color: #000080;\">\"changed\": false,<\/span>\r\n<span style=\"color: #000080;\">\"ping\": \"pong\"<\/span>\r\n<span style=\"color: #000080;\">}<\/span><\/pre>\n<p>&nbsp;<\/p>\n<h3>Configuring SSH connection between Ubuntu and routers which launched in GNS3<\/h3>\n<ol>\n<li>Software version of my virtual machines<\/li>\n<\/ol>\n<p>In my case I&#8217;m using Ubuntu 22.04 LTS:<\/p>\n<pre>Linux virtualbox 6.2.0-32-generic #32~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 18 10:40:13 UTC 2 x86_64 x86_64 x86_64 GNU\/Linux<\/pre>\n<p>and Cisco IOS C3745-ADVIPSERVICESK9-M:<\/p>\n<pre>Cisco IOS Software, 3700 Software (C3745-ADVIPSERVICESK9-M), Version 12.4(25d), RELEASE SOFTWARE (fc1)\r\nIMAGE in GNS3: c3745-adventerprisek9-mz.SW.image<\/pre>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-176\" src=\"http:\/\/www.netasic.com\/wp-content\/uploads\/2023\/09\/ansible_GNS3.png\" alt=\"\" width=\"597\" height=\"607\" srcset=\"https:\/\/www.netasic.com\/wp-content\/uploads\/2023\/09\/ansible_GNS3.png 597w, https:\/\/www.netasic.com\/wp-content\/uploads\/2023\/09\/ansible_GNS3-295x300.png 295w\" sizes=\"(max-width: 597px) 100vw, 597px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>2. SSH configuration on Ubuntu:<\/p>\n<pre><span style=\"color: #ff6600;\"><strong>ansible@virtualbox:~\/.ssh$ pwd<\/strong><\/span>\r\n\r\n<span style=\"color: #ff6600;\">\/home\/ansible\/.ssh        #\"ansible\" here is my user on Ubuntu<\/span>\r\n\r\n<span style=\"color: #000080;\"><strong>ansible@virtualbox:~\/.ssh$ cat config<\/strong><\/span>\r\n\r\n<span style=\"color: #000080;\">#Host 10.0.0.10<\/span>\r\n\r\n<span style=\"color: #000080;\"># KexAlgorithms +diffie-hellman-group1-sha1<\/span>\r\n\r\n\r\n\r\n\r\n<span style=\"color: #000080;\">Host 10.0.0.10<\/span>\r\n\r\n<span style=\"color: #000080;\">User cisco<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 \u00a0 \u00a0 PubkeyAcceptedAlgorithms +ssh-rsa<\/span>\r\n\r\n<span style=\"color: #000080;\">HostkeyAlgorithms +ssh-rsa<\/span>\r\n\r\n<span style=\"color: #000080;\">SendEnv LANG LC_*<\/span>\r\n\r\n<span style=\"color: #000080;\">Ciphers +aes256-cbc<\/span>\r\n\r\n<span style=\"color: #000080;\">KexAlgorithms +diffie-hellman-group1-sha1<\/span>\r\n\r\n\r\n\r\n\r\n<span style=\"color: #000080;\">Host 10.0.0.1<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 User cisco<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 \u00a0 \u00a0 PubkeyAcceptedAlgorithms +ssh-rsa<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 \u00a0 \u00a0 HostkeyAlgorithms +ssh-rsa<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 \u00a0 \u00a0 SendEnv LANG LC_*<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 \u00a0 \u00a0 Ciphers +aes256-cbc<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 \u00a0 \u00a0 KexAlgorithms +diffie-hellman-group1-sha1<\/span>\r\n\r\n\r\n\r\n\r\n<span style=\"color: #000080;\">Host 10.0.0.2<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 User cisco<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 \u00a0 \u00a0 PubkeyAcceptedAlgorithms +ssh-rsa<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 \u00a0 \u00a0 HostkeyAlgorithms +ssh-rsa<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 \u00a0 \u00a0 SendEnv LANG LC_*<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 \u00a0 \u00a0 Ciphers +aes256-cbc<\/span>\r\n\r\n<span style=\"color: #000080;\">\u00a0 \u00a0 \u00a0 \u00a0 KexAlgorithms +diffie-hellman-group1-sha1<\/span>\r\n\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>3. SSH configuration of routers:<\/p>\n<pre><span style=\"color: #000080;\">username cisco privilege 15 secret 5 $1$6ATn$K\/\/vtl9HPK8wx3bq7PnvB.<\/span>\r\n<span style=\"color: #000080;\">!<\/span>\r\n<span style=\"color: #000080;\">ip ssh version 2<\/span>\r\n<span style=\"color: #000080;\">!<\/span>\r\n<span style=\"color: #000080;\">line vty 0 4<\/span>\r\n<span style=\"color: #000080;\">login local<\/span>\r\n<span style=\"color: #000080;\">transport input ssh<\/span>\r\n<span style=\"color: #000080;\">!<\/span>\r\n<span style=\"color: #000080;\">!<\/span><\/pre>\n<p><a href=\"https:\/\/www.netasic.com\/index.php\/2023\/09\/30\/ansible-network-topology-and-configuration\/\" target=\"_blank\" rel=\"noopener\">Continue reading<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ansible is an agentless automation tool, which allow dramatically reduce the time required for configuring our networks systems. We can automate many of our daily tasks and even dynamically manage of our configuration what we call orchestration. Let&#8217;s start Getting &hellip; <a href=\"https:\/\/www.netasic.com\/index.php\/2023\/09\/23\/getting-started-with-network-automation-using-ansible\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-161","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.netasic.com\/index.php\/wp-json\/wp\/v2\/posts\/161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.netasic.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.netasic.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.netasic.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.netasic.com\/index.php\/wp-json\/wp\/v2\/comments?post=161"}],"version-history":[{"count":34,"href":"https:\/\/www.netasic.com\/index.php\/wp-json\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":337,"href":"https:\/\/www.netasic.com\/index.php\/wp-json\/wp\/v2\/posts\/161\/revisions\/337"}],"wp:attachment":[{"href":"https:\/\/www.netasic.com\/index.php\/wp-json\/wp\/v2\/media?parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.netasic.com\/index.php\/wp-json\/wp\/v2\/categories?post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.netasic.com\/index.php\/wp-json\/wp\/v2\/tags?post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}