{"id":51633,"date":"2020-01-09T11:43:18","date_gmt":"2020-01-09T16:43:18","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/?p=51633"},"modified":"2021-08-16T15:43:10","modified_gmt":"2021-08-16T19:43:10","slug":"add-hosts-to-ansible-inventory","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/","title":{"rendered":"How to Add Hosts to Your Ansible Inventory"},"content":{"rendered":"\n<p>Every server you manage with <a href=\"https:\/\/www.inmotionhosting.com\/ansible\">Ansible<\/a> needs to be added to your Inventory.yml file. Your Ansible inventory organizes these remote hosts into groups for easier configuration within your playbooks.<\/p>\n\n\n\n<p>Below we cover how to <a href=\"#edit\">add hosts to your Ansible inventory<\/a>, <a href=\"#sample\">sample groups<\/a>, and <a href=\"#test\">testing an inventory connection<\/a>.<\/p>\n\n\n\n<p class=\"alert alert-info\">Manage your Ansible inventory with our reliable <a href=\"https:\/\/www.inmotionhosting.com\/cloud-vps\">Cloud Server Hosting<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"edit\">Edit Your Ansible Inventory.yml<\/h2>\n\n\n\n<ol class=\"article_list wp-block-list\"><li><a href=\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/how-to-login-ssh\/\">Log into SSH<\/a><\/li><li><a href=\"https:\/\/www.inmotionhosting.com\/support\/server\/linux\/using-the-linux-cd-command\/\">Navigate to your Ansible directory<\/a><\/li><li>Edit the inventory.yml file: <code>nano inventory.yml<\/code><\/li><li>Copy both code blocks below within your inventory as needed: <kbd>Ctrl<\/kbd> + <kbd>V<\/kbd><\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"sample\">Sample Inventory.yml<\/h3>\n\n\n\n<p>The <code>all<\/code> group is the first group and includes all hosts listed within your inventory. The <code>vars<\/code> indicator allows global default variables for using the group. The variables in the example below state to connect to remote hosts via <strong>SSH<\/strong> as user <strong>root<\/strong>. The <code>ansible_connection<\/code> can be set to any <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/plugins\/connection.html\">Ansible connection plugin<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>all:\n  vars:\n    ansible_connection: ssh\n    ansible_user: root<\/code><\/pre>\n\n\n\n<p>Other groups can follow the format below. Keep in mind, there are other ways to <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/intro_inventory.html#adding-variables-to-inventory\">build your Ansible inventory<\/a> with groups and variables. Hosts can be defined as a domain or <a href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/cpanel\/how-to-find-your-shared-ip-address-of-your-server-in-cpanel\/\">server IP address<\/a>.<\/p>\n\n\n\n<p class=\"alert alert-info\">Only one host is required for a playbook to run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>group-1:\n  hosts:\n    domain-1.tld:\n      example-var-1: # variable affects domain-1.tld only\n    domain-2.tld:\n  vars:\n    example-var-2: # variable affects all hosts within group<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"test\">Test Your Inventory<\/h2>\n\n\n\n<p>After editing your inventory file, test your Ansible connection to your remote host: <code>ansible -m ping [host\/group] -i inventory.yml<\/code><\/p>\n\n\n\n<p>The results should resemble the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[Any warnings will be listed first]\ndomain.com | SUCCESS => {\n   \"ansible_facts\": {\n       \"discovered_interpreter_python\": \"\/usr\/local\/bin\/python [version]\"\n   },\n   \"changed\": false,\n   \"ping\": \"pong\"\n}<\/code><\/pre>\n\n\n\n<p>Learn more about IT automation in our <a href=\"https:\/\/www.inmotionhosting.com\/support\/ansible\/\">Ansible Education Channel<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every server you manage with Ansible needs to be added to your Inventory.yml file. Your Ansible inventory organizes these remote hosts into groups for easier configuration within your playbooks. Below we cover how to add hosts to your Ansible inventory, sample groups, and testing an inventory connection. Manage your Ansible inventory with our reliable Cloud<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/\"> Read More ><\/a><\/p>\n","protected":false},"author":57014,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4349],"tags":[],"class_list":["post-51633","post","type-post","status-publish","format-standard","hentry","category-ansible"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Add Hosts to Your Ansible Inventory | InMotion Hosting<\/title>\n<meta name=\"description\" content=\"Learn how to add hosts to your Ansible inventory, create groups, and test an inventory connection.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Add Hosts to Your Ansible Inventory | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"Learn how to add hosts to your Ansible inventory, create groups, and test an inventory connection.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-09T16:43:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-16T19:43:10+00:00\" \/>\n<meta name=\"author\" content=\"InMotion Hosting Contributor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InMotion Hosting Contributor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/\"},\"author\":{\"name\":\"InMotion Hosting Contributor\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/f9a4fc454cd1df128ee8e898d30d4644\"},\"headline\":\"How to Add Hosts to Your Ansible Inventory\",\"datePublished\":\"2020-01-09T16:43:18+00:00\",\"dateModified\":\"2021-08-16T19:43:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/\"},\"wordCount\":225,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"articleSection\":[\"Ansible Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/\",\"name\":\"How to Add Hosts to Your Ansible Inventory | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2020-01-09T16:43:18+00:00\",\"dateModified\":\"2021-08-16T19:43:10+00:00\",\"description\":\"Learn how to add hosts to your Ansible inventory, create groups, and test an inventory connection.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Add Hosts to Your Ansible Inventory\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/f9a4fc454cd1df128ee8e898d30d4644\",\"name\":\"InMotion Hosting Contributor\",\"description\":\"InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/inmotion-hosting\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/InMotionHosting\"],\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/inmotion-hosting-contributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Add Hosts to Your Ansible Inventory | InMotion Hosting","description":"Learn how to add hosts to your Ansible inventory, create groups, and test an inventory connection.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/","og_locale":"en_US","og_type":"article","og_title":"How to Add Hosts to Your Ansible Inventory | InMotion Hosting","og_description":"Learn how to add hosts to your Ansible inventory, create groups, and test an inventory connection.","og_url":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2020-01-09T16:43:18+00:00","article_modified_time":"2021-08-16T19:43:10+00:00","author":"InMotion Hosting Contributor","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"InMotion Hosting Contributor","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/"},"author":{"name":"InMotion Hosting Contributor","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/f9a4fc454cd1df128ee8e898d30d4644"},"headline":"How to Add Hosts to Your Ansible Inventory","datePublished":"2020-01-09T16:43:18+00:00","dateModified":"2021-08-16T19:43:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/"},"wordCount":225,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"articleSection":["Ansible Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/","url":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/","name":"How to Add Hosts to Your Ansible Inventory | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2020-01-09T16:43:18+00:00","dateModified":"2021-08-16T19:43:10+00:00","description":"Learn how to add hosts to your Ansible inventory, create groups, and test an inventory connection.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"How to Add Hosts to Your Ansible Inventory"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/f9a4fc454cd1df128ee8e898d30d4644","name":"InMotion Hosting Contributor","description":"InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!","sameAs":["https:\/\/www.linkedin.com\/company\/inmotion-hosting\/","https:\/\/x.com\/https:\/\/twitter.com\/InMotionHosting"],"url":"https:\/\/www.inmotionhosting.com\/support\/author\/inmotion-hosting-contributor\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":null,"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/51633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/57014"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=51633"}],"version-history":[{"count":9,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/51633\/revisions"}],"predecessor-version":[{"id":83056,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/51633\/revisions\/83056"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=51633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=51633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=51633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}