{"id":57131,"date":"2020-07-07T13:56:38","date_gmt":"2020-07-07T17:56:38","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/?p=57131"},"modified":"2020-07-07T13:56:39","modified_gmt":"2020-07-07T17:56:39","slug":"using-ansible-modules","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/","title":{"rendered":"Using Ansible Modules"},"content":{"rendered":"\n<p>One of the ways Ansible executes specific tasks is through the use of <strong>modules<\/strong>. Modules are discrete units of code that can be used in an <a rel=\"noreferrer noopener\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/getting-started-with-ansible-galaxy\/\" target=\"_blank\">Ansible playbook<\/a> or directly from a command-line interface. By leveraging Ansible modules you can easily manage and maintain your Ansible deployments. In this article, we will outline how Ansible Modules are used as well as provide some examples of modules and their various functionalities.&nbsp;<\/p>\n\n\n\n<p>Topics Include:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#command\">Using Ansible Modules from Command-Line<\/a><\/li><li><a href=\"#playbook\">Using Ansible Modules in Playbooks<\/a><\/li><\/ul>\n\n\n\n<p class=\"alert alert-info\">Start using Ansible modules with <a href=\"https:\/\/www.inmotionhosting.com\/ansible\" target=\"_blank\" rel=\"noreferrer noopener\">Ansible<\/a> today!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"command\">Using Ansible Modules from Command-Line<\/h2>\n\n\n\n<p>As previously mentioned, Ansible modules can be used from the command-line or in an Ansible playbook. When executing an Ansible module from the command-line, you can sometimes supply additional arguments to further modify how the module is executed by Ansible. For example, if you want to use the Commands Module \u201ccommand\u201d to output a simple text message on your server, you would use the following command:<\/p>\n\n\n\n<p><code>ansible localhost -m command -a \u201c\/bin\/echo hello, world!\u201d<\/code><\/p>\n\n\n\n<p>In this example, <strong>-m<\/strong> is a <strong>command-line argument<\/strong> that specifies that a module is being called. The argument <strong>-a<\/strong> simply passes along the other arguments specified in the command.&nbsp;<br><br>Additionally, most Ansible modules support space <code>delimited key=value<\/code> arguments. For example, if you want to use the system module <strong>service<\/strong> to start the HTTP service on your server, you can use the following command:<\/p>\n\n\n\n<p><code>ansible webservers -i inventory.yml -m service -a \"name=httpd state=started\"<\/code><\/p>\n\n\n\n<p>As you can see in this example, you can specify the name of the service as well as the desired state of that service using the <code>key=value<\/code> argument format. The argument <strong>-i<\/strong> specifies the <a href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/add-hosts-to-ansible-inventory\/\" target=\"_blank\" rel=\"noreferrer noopener\">inventory file<\/a> being used to determine which servers are included in the<strong> webservers<\/strong> group.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"playbook\">Using Ansible Modules in Playbooks<\/h2>\n\n\n\n<p>Using modules in Ansible playbooks largely functions the same way as it does in the command-line, with the main difference being that the modules will be stored in the playbook file rather than executed directly on the command-line. For example, if we wish to reboot a server immediately just as we did from the command-line, we would include the following lines in our playbook file:<\/p>\n\n\n\n<p><code>-name: reboot the servers<br> command: \/sbin\/reboot -t now<\/code><\/p>\n\n\n\n<p>While you can reboot your server using the command module, there is also a specific module that will allow you to reboot your server, called the reboot module. This can be used in a playbook the same as the command module:<\/p>\n\n\n\n<p><code>-name: reboot the servers<br> reboot:&nbsp;<\/code><\/p>\n\n\n\n<p>Even though both modules accomplish the same goal, the reboot module is specific while the command module is more generalized.&nbsp;<\/p>\n\n\n\n<p>As all modules return JSON format data, you can write modules in any programming language, allowing for greater flexibility in development and deployment. To review a list of all available Ansible Modules, you can use the following command:<\/p>\n\n\n\n<p><code>ansible-doc -l<\/code><\/p>\n\n\n\n<p>Now that you know how to use Ansible modules, you will likely want to familiarize yourself with some of the existing modules on this list. By integrating these modules into your workflow you can further enhance your Ansible deployment and automation strategies.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the ways Ansible executes specific tasks is through the use of modules. Modules are discrete units of code that can be used in an Ansible playbook or directly from a command-line interface. By leveraging Ansible modules you can easily manage and maintain your Ansible deployments. In this article, we will outline how Ansible<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/\"> 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-57131","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>Using Ansible Modules | InMotion Hosting Support Center<\/title>\n<meta name=\"description\" content=\"In this article, we will outline how Ansible Modules are used as well as provide some examples of modules and their various functionalities.\" \/>\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\/using-ansible-modules\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Ansible Modules | InMotion Hosting Support Center\" \/>\n<meta property=\"og:description\" content=\"In this article, we will outline how Ansible Modules are used as well as provide some examples of modules and their various functionalities.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/\" \/>\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-07-07T17:56:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-07T17:56:39+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=\"3 minutes\" \/>\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\/using-ansible-modules\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/\"},\"author\":{\"name\":\"InMotion Hosting Contributor\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/f9a4fc454cd1df128ee8e898d30d4644\"},\"headline\":\"Using Ansible Modules\",\"datePublished\":\"2020-07-07T17:56:38+00:00\",\"dateModified\":\"2020-07-07T17:56:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/\"},\"wordCount\":485,\"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\/using-ansible-modules\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/\",\"name\":\"Using Ansible Modules | InMotion Hosting Support Center\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2020-07-07T17:56:38+00:00\",\"dateModified\":\"2020-07-07T17:56:39+00:00\",\"description\":\"In this article, we will outline how Ansible Modules are used as well as provide some examples of modules and their various functionalities.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using Ansible Modules\"}]},{\"@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":"Using Ansible Modules | InMotion Hosting Support Center","description":"In this article, we will outline how Ansible Modules are used as well as provide some examples of modules and their various functionalities.","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\/using-ansible-modules\/","og_locale":"en_US","og_type":"article","og_title":"Using Ansible Modules | InMotion Hosting Support Center","og_description":"In this article, we will outline how Ansible Modules are used as well as provide some examples of modules and their various functionalities.","og_url":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2020-07-07T17:56:38+00:00","article_modified_time":"2020-07-07T17:56:39+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":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/"},"author":{"name":"InMotion Hosting Contributor","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/f9a4fc454cd1df128ee8e898d30d4644"},"headline":"Using Ansible Modules","datePublished":"2020-07-07T17:56:38+00:00","dateModified":"2020-07-07T17:56:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/"},"wordCount":485,"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\/using-ansible-modules\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/","url":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/","name":"Using Ansible Modules | InMotion Hosting Support Center","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2020-07-07T17:56:38+00:00","dateModified":"2020-07-07T17:56:39+00:00","description":"In this article, we will outline how Ansible Modules are used as well as provide some examples of modules and their various functionalities.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/ansible\/using-ansible-modules\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"Using Ansible Modules"}]},{"@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\/57131","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=57131"}],"version-history":[{"count":9,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/57131\/revisions"}],"predecessor-version":[{"id":57183,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/57131\/revisions\/57183"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=57131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=57131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=57131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}