{"id":22750,"date":"2023-03-31T12:56:18","date_gmt":"2023-03-31T10:56:18","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=22750"},"modified":"2025-04-04T13:47:34","modified_gmt":"2025-04-04T11:47:34","slug":"specify-hosts-in-ansible-playbook-command-line","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/","title":{"rendered":"Specify hosts in ansible-playbook command line"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-introduction\">Introduction<\/h2>\n\n\n\n<p><a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/playbook_guide\/playbooks_intro.html\">Playbook<\/a> are a key element of Ansible. You specify which roles and tasks will run on your hosts and groups.<br>Each play of the playbook must have its parameter hosts set.<\/p>\n\n\n\n<p>Here is a quick example of different hosts values that you might be familiar with:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n---\n- name: My play targeting all hosts \n  hosts: all\n  tasks:\n    - debug:\n        msg: &#039;Running on all hosts&#039;\n\n- name: Targeting multiple groups called dbservers and webservers\n  hosts:\n  - dbservers\n  - webservers  \n  tasks:\n    - debug:\n        msg: &#039;Running on all dbservers and webserver&#039;\n\n- name: Targeting only one host called dbserver-01\n  hosts: dbserver-01\n  tasks:  \n    - debug:\n        msg: &#039;Running on one hosts&#039;\n\n- name: Running on the Ansible server\n  hosts: localhost\n  connection: local\n  tasks:\n    - debug:\n        msg: &#039;Running on localhost&#039;\n<\/pre><\/div>\n\n\n<p>If you are developing with Ansible, you probably already have written a playbook. You might also have duplicated a playbook to target different groups and hosts due to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Some use cases<\/li>\n\n\n\n<li>The organization of your Ansible and inventories files<\/li>\n\n\n\n<li>Any others reasons<\/li>\n<\/ul>\n\n\n\n<p>This article will focus on the different ways we can provide the hosts parameter to avoid handling multiple playbook files.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<p>For all the following examples, you can use this &#8216;hosts&#8217; file and replace all machine hostnames with your own.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n# hosts\n&#x5B;dbservers]\ndbserver-01\ndbserver-02\n\n&#x5B;webservers]\nwebserver-01\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-ansible-extra-variable-specify-hosts-on-the-command-line\">Ansible extra variable &#8211; Specify hosts on the command line<\/h2>\n\n\n\n<p>The first idea that may come to mind is to use an <strong>Ansible variable<\/strong> and pass it as an <strong>extra vars<\/strong>.<br>Here I name the variable <strong>my_playbook_hosts<\/strong> and ask to target a group and a host.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n# extravars.yml\n---\n- name: My play targeting hosts specified in the command line \n  hosts: &#039;{{ my_playbook_hosts }}&#039;\n  tasks:\n    - debug:\n        msg: &#039;Running on hosts specified by my extra vars&#039;\n\n<\/pre><\/div>\n\n\n<p>Then you can simply run the <strong>ansible-playbook<\/strong> command with the <strong>option \u2010\u2010extra-vars<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nansible-playbook -i hosts extravars.yml -e &#039;my_playbook_hosts=dbservers&#039;\n<\/pre><\/div>\n\n\n<p>This solution works fine, you just need to come up with a new variable and be sure that its name is not already used by Ansible or in your existing roles\/tasks (except if it is expected).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-default-value\">Default value<\/h4>\n\n\n\n<p>Using the Jinja2 &#8216;default&#8217; filter, you can specify a default value.<br>That way, if you don&#8217;t provide the extra variable, the playbook will run on the default value hosts. Here for example with the group &#8216;dbservers&#8217;: <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n  hosts: &#039;{{ my_playbook_hosts | default(&quot;dbservers&quot;) }}&#039;\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"h-common-pattern\">Common pattern<\/h4>\n\n\n\n<p>A pattern can be used for targeting hosts and groups.<br>More information can be read in the Ansible official <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/inventory_guide\/intro_patterns.html#common-patterns\">documentation<\/a>. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"400\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-1024x400.png\" alt=\"Screenshot of ansible documentation about common patterns\" class=\"wp-image-22772\" style=\"width:840px;height:328px\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-1024x400.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-300x117.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-768x300.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-1536x600.png 1536w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern.png 1732w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Link to official documentation: <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/inventory_guide\/intro_patterns.html#common-patterns\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/docs.ansible.com\/ansible\/latest\/inventory_guide\/intro_patterns.html#common-patterns<\/a><\/figcaption><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# Target group webservers and host dbserver-01.\nansible-playbook -i hosts extravars.yml -e &#039;my_playbook_hosts=webservers,dbserver-01&#039;\n\n# Target group dbservers, excluding host webserver-01.\nansible-playbook -i hosts extravars.yml -e &#039;my_playbook_hosts=dbservers,!webserver-01&#039;\n\n# Target nothing as all is negate.\nansible-playbook -i hosts blogtest.yml -e &#039;my_playbook_hosts=!all,webserver-01&#039;\n<\/pre><\/div>\n\n\n<p>Those patterns can also be used in the playbook file directly:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n- name: Targeting multiple groups called dbservers and webservers\n  hosts: dbservers,webservers  \n\n- name: Targeting all except webservers\n  hosts: &#039;all,!webservers&#039;  \n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"h-negate\">Negate<\/h4>\n\n\n\n<p>About negating hosts and groups, always use single quotes to prevent bash interpolation or syntax error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-ansible-limit-limit-on-which-host-group-it-runs\">Ansible limit &#8211; Limit on which host\/group it runs<\/h2>\n\n\n\n<p>Command ansible-playbook has an option which is <strong>\u2010\u2010limit<\/strong> or <strong>-l<\/strong>, which further limits selected hosts to an additional pattern.<\/p>\n\n\n\n<p>Let&#8217;s say your playbook runs on &#8216;dbservers&#8217; group, with limit, you can restrict further the hosts or groups on which it should run: <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n# limit.yml\n---\n- name: My play targeting all dbservers\n  hosts: dbservers\n  tasks:\n    - debug:\n        msg: &#039;Running all dbservers&#039;\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# Will only target host dbserver-02, if its belong to dbservers\nansible-playbook -i hosts limit.yml -l dbserver-02 \n\n# Will target dbservers group, except the hosts dbserver-02\nansible-playbook -i hosts limit.yml -l &#039;!dbserver-02&#039;\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n# limit2.yml\n---\n- name: Play running on all hosts\n  hosts: all\n  tasks:\n    - debug:\n        msg: &#039;Running on all hosts&#039;\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# Will only target groups webservers and host dbserver-01\nansible-playbook -i hosts limit2.yml -l &#039;webservers,dbserver-01&#039;\n<\/pre><\/div>\n\n\n<p>I personnaly prefer this method to the extra vars, as it doesn&#8217;t require adding a new additional variable and doesn&#8217;t require modifying the existing playbook. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-diving-more-into-ansible-playbook-limit\">Diving more into ansible-playbook \u2010\u2010limit<\/h3>\n\n\n\n<p>You can find a lot of examples of <strong>ansible-playbook \u2010\u2010limit<\/strong> with a playbook targeting <strong>all hosts (hosts: all)<\/strong>.<\/p>\n\n\n\n<p><br>That is something that bothered me a little depending on the playbook usage.<br>If the playbook is to be used on all hosts every time, with rare occasions to target only a specific host and\/or group, then it should be good.<\/p>\n\n\n\n<p><br>On the contrary, if the playbook is to always be run to specific hosts and groups every time, then it might be dangerous to set the &#8216;hosts&#8217; to &#8216;all&#8217; or any others groups by default.<br>If by accident, the <strong>\u2010\u2010limit<\/strong> option is forgotten, your playbook will be run on the &#8216;hosts&#8217; specified on the playbook file and might cause serious issues.<\/p>\n\n\n\n<p>Here is a <strong>safer solution<\/strong> that I find elegant and good.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-ansible-limit-specify-hosts-on-the-command-line\">Ansible limit &#8211; Specify hosts on the command line<\/h3>\n\n\n\n<p>With this method, <strong>the playbook only runs on the pattern you provide<\/strong> in the limit option.<br>It is exactly the same way as how <strong>\u2010\u2010extra-vars <\/strong>work, but in this situation, you don&#8217;t need to create a new variable.<\/p>\n\n\n\n<p>The value specified in <strong>\u2010\u2010limit<\/strong> is stored in the variable <strong>ansible_limit<\/strong>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n# safer.yml\n---\n- name: Play running only on the pattern given by the option --limit\n  hosts: &#039;{{ ansible_limit | default(omit) }}&#039;\n  tasks:\n    - debug:\n        msg: &#039;Running on hosts specified by limit&#039;\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# Will target all host\nansible-playbook -i hosts safer.yml -l &#039;all&#039;\n\n# Will target group dbservers\nansible-playbook -i hosts safer.yml -l &#039;dbservers&#039;\n\n# Will target group webservers and host dbserver-01\nansible-playbook -i hosts safer.yml -l &#039;webservers,dbserver-01&#039;\n\n# Will target all except dbservers \nansible-playbook -i hosts safer.yml -l &#039;all,!dbservers&#039;\n<\/pre><\/div>\n\n\n<p>The special keyword omit in default is a special variable that allows omitting the parameters, causing the playbook to run without crashing. <br>The results will be a skip of the play.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nansible-playbook -i hosts safer.yml\n&#x5B;WARNING]: Could not match supplied host pattern, ignoring: None\n\nPLAY &#x5B;Play running only on the pattern given by the option --limit] **************************************************************************\nskipping: no hosts matched\n\nPLAY RECAP ****************************************************************************************************************************************************\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>In conclusion, the best method will always vary and depend on different factors, so try out the different methods and pick those suitable for your needs.<\/p>\n\n\n\n<p>You are now able to specify via the command line which hosts\/groups to apply your playbook! <\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<p>Learn more on Ansible with our Training course:&nbsp;<a href=\"https:\/\/www.dbi-services.com\/en\/courses\/ansible-basics\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.dbi-services.com\/en\/courses\/ansible-basics\/&nbsp;<\/a><\/p>\n\n\n\n<p>And check our other blog articles <a href=\"https:\/\/www.dbi-services.com\/blog\/category\/devops\/ansible\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.dbi-services.com\/blog\/category\/devops\/ansible\/<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Playbook are a key element of Ansible. You specify which roles and tasks will run on your hosts and groups.Each play of the playbook must have its parameter hosts set. Here is a quick example of different hosts values that you might be familiar with: If you are developing with Ansible, you probably already [&hellip;]<\/p>\n","protected":false},"author":132,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1321,1320],"tags":[150,2850,151],"type_dbi":[3077],"class_list":["post-22750","post","type-post","status-publish","format-standard","hentry","category-ansible","category-devops","tag-ansible","tag-ansible-playbook","tag-devops","type-ansible"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Specify hosts in ansible-playbook command line - dbi Blog<\/title>\n<meta name=\"description\" content=\"Ansible limit - Specify hosts on the command line. With this method, the playbook only run on the pattern you provide in the limit option.\" \/>\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.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Specify hosts in ansible-playbook command line\" \/>\n<meta property=\"og:description\" content=\"Ansible limit - Specify hosts on the command line. With this method, the playbook only run on the pattern you provide in the limit option.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-31T10:56:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-04T11:47:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1732\" \/>\n\t<meta property=\"og:image:height\" content=\"676\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"K\u00e9vin Keovilay\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"K\u00e9vin Keovilay\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/\"},\"author\":{\"name\":\"K\u00e9vin Keovilay\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7\"},\"headline\":\"Specify hosts in ansible-playbook command line\",\"datePublished\":\"2023-03-31T10:56:18+00:00\",\"dateModified\":\"2025-04-04T11:47:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/\"},\"wordCount\":719,\"commentCount\":2,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-1024x400.png\",\"keywords\":[\"Ansible\",\"ansible-playbook\",\"DevOps\"],\"articleSection\":[\"Ansible\",\"DevOps\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/\",\"name\":\"Specify hosts in ansible-playbook command line - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-1024x400.png\",\"datePublished\":\"2023-03-31T10:56:18+00:00\",\"dateModified\":\"2025-04-04T11:47:34+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7\"},\"description\":\"Ansible limit - Specify hosts on the command line. With this method, the playbook only run on the pattern you provide in the limit option.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#primaryimage\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-1024x400.png\",\"contentUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-1024x400.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Specify hosts in ansible-playbook command line\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7\",\"name\":\"K\u00e9vin Keovilay\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g\",\"caption\":\"K\u00e9vin Keovilay\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/kevinkeovilay\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Specify hosts in ansible-playbook command line - dbi Blog","description":"Ansible limit - Specify hosts on the command line. With this method, the playbook only run on the pattern you provide in the limit option.","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.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/","og_locale":"en_US","og_type":"article","og_title":"Specify hosts in ansible-playbook command line","og_description":"Ansible limit - Specify hosts on the command line. With this method, the playbook only run on the pattern you provide in the limit option.","og_url":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/","og_site_name":"dbi Blog","article_published_time":"2023-03-31T10:56:18+00:00","article_modified_time":"2025-04-04T11:47:34+00:00","og_image":[{"width":1732,"height":676,"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern.png","type":"image\/png"}],"author":"K\u00e9vin Keovilay","twitter_card":"summary_large_image","twitter_misc":{"Written by":"K\u00e9vin Keovilay","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/"},"author":{"name":"K\u00e9vin Keovilay","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7"},"headline":"Specify hosts in ansible-playbook command line","datePublished":"2023-03-31T10:56:18+00:00","dateModified":"2025-04-04T11:47:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/"},"wordCount":719,"commentCount":2,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-1024x400.png","keywords":["Ansible","ansible-playbook","DevOps"],"articleSection":["Ansible","DevOps"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/","url":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/","name":"Specify hosts in ansible-playbook command line - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-1024x400.png","datePublished":"2023-03-31T10:56:18+00:00","dateModified":"2025-04-04T11:47:34+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7"},"description":"Ansible limit - Specify hosts on the command line. With this method, the playbook only run on the pattern you provide in the limit option.","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-1024x400.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/02\/screenshot-ansible-common-pattern-1024x400.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/specify-hosts-in-ansible-playbook-command-line\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Specify hosts in ansible-playbook command line"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7","name":"K\u00e9vin Keovilay","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g","caption":"K\u00e9vin Keovilay"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/kevinkeovilay\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/22750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/132"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=22750"}],"version-history":[{"count":33,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/22750\/revisions"}],"predecessor-version":[{"id":37904,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/22750\/revisions\/37904"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=22750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=22750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=22750"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=22750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}