{"id":103,"date":"2022-03-28T22:01:08","date_gmt":"2022-03-29T02:01:08","guid":{"rendered":"http:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/?p=103"},"modified":"2024-10-11T09:35:07","modified_gmt":"2024-10-11T13:35:07","slug":"ansible-cheat-sheet","status":"publish","type":"post","link":"https:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/?p=103","title":{"rendered":"ansible cheat sheet"},"content":{"rendered":"\n<figure class=\"wp-block-table is-style-regular\"><table><tbody><tr><td><br><strong>Command<\/strong><\/td><\/tr><tr><td>ansible-playbook file.yaml<\/td><td>Run an Ansible playbook called file.yaml<\/td><\/tr><tr><td><br><strong>Authentication options<\/strong><\/td><\/tr><tr><td>&#8211;user, -u &lt;username&gt;<\/td><td>Log in as username<\/td><\/tr><tr><td>&#8211;private-key, &#8211;key-file &lt;key&gt;<\/td><td>Log in using SSH key (usually in ~\/.ssh)<\/td><\/tr><tr><td>&#8211;ssh-extra-args<\/td><td>Pass extra command options to SSH<\/td><\/tr><tr><td>&#8211;vault-id &lt;id&gt;<\/td><td>Use vault identity ID<\/td><\/tr><tr><td>&#8211;vault-password-file &lt;key&gt;<\/td><td>Use vault password file key<\/td><\/tr><tr><td>&#8211;ask-vault-pass<\/td><td>Prompt for a vault password<\/td><\/tr><tr><td>&#8211;become<\/td><td>Escalate privileges<\/td><\/tr><tr><td>&#8211;ask-become-pass<\/td><td>Prompt for a password for become<\/td><\/tr><tr><td>&#8211;become-method<\/td><td>Escalate privilege using a specific method<\/td><\/tr><tr><td>ansible-doc \u2013-type foo &#8211;list<\/td><td>List choices for become, connection, and other Ansible options<\/td><\/tr><tr><td><br><strong>Control options<\/strong><\/td><\/tr><tr><td>&#8211;syntax-check<\/td><td>Verify syntax of a playbook, but do not run it<\/td><\/tr><tr><td>&#8211;list-hosts<\/td><td>Show hosts listed in a playbook<\/td><\/tr><tr><td>&#8211;list-tasks<\/td><td>Show tasks defined in a playbook<\/td><\/tr><tr><td>&#8211;start-at-task &lt;task_name&gt;<\/td><td>Run playbook starting at task name<\/td><\/tr><tr><td>&#8211;check<\/td><td>Run the playbook but don\u2019t make changes<\/td><\/tr><tr><td>&#8211;diff<\/td><td>Show diffs for what changes are made<\/td><\/tr><tr><td>&#8211;module-path<\/td><td>Prepend colon-separated path to default path<\/td><\/tr><tr><td>&#8211;connection &lt;method&gt;<\/td><td>Connect over method<\/td><\/tr><tr><td><br><strong>Playbook and YAML<\/strong><\/td><\/tr><tr><td>Parameter: value<\/td><td>A YAML mapping entry is a key and a value<\/td><\/tr><tr><td>&#8211; foo<\/td><td>A YAML sequence entry is an itemized list<\/td><\/tr><tr><td>&#8211; bar<\/td><td><br><\/td><\/tr><tr><td>&#8211; baz<\/td><td><br><\/td><\/tr><tr><td>Distro:<\/td><td>A mapping entry can contain a sequence<\/td><\/tr><tr><td>&#8211; Fedora<\/td><td><br><\/td><\/tr><tr><td>&#8211; RHEL<\/td><td><br><\/td><\/tr><tr><td>&#8211; Debian<\/td><td><br><\/td><\/tr><tr><td>&#8211; Slackware<\/td><td><br><\/td><\/tr><tr><td>OS:<\/td><td>Sequence items can contain mappings<\/td><\/tr><tr><td>&#8211; Linux: Fedora<\/td><td><br><\/td><\/tr><tr><td>&#8211; BSD: NetBSD<\/td><td><br><\/td><\/tr><tr><td><br><strong>Playbook structure<\/strong><\/td><\/tr><tr><td>&#8212;<\/td><td>YAML files start with three dashes<\/td><\/tr><tr><td>&#8211; name: \u201cMy play\u201d<\/td><td>Use the name mapping to name your play<\/td><\/tr><tr><td>hosts: all<\/td><td>Indent, and define which hosts the play runs on. List target hosts in etc\/ansible\/hosts<\/td><\/tr><tr><td>tasks:<\/td><td>Open a tasks mapping, which will contain a sequence<\/td><\/tr><tr><td>&#8211; name:<\/td><td>\u201cMy task\u201d Give the task a name with the name mapping<\/td><\/tr><tr><td>some_module:<\/td><td>Import a module as a new mapping containing a sequence of parameters. Find required and optional parameters in the module\u2019s documentation.<\/td><\/tr><tr><td>path: \u2018\/example\/\u2019<\/td><td>Parameters are usually mappings using the command option as the key and an argument as the value.<\/td><\/tr><tr><td>&#8211; name: \u201cMy other task\u201d<\/td><td>A play may contain more than one task<\/td><\/tr><tr><td>other_module:<\/td><td>A task usually imports a module<\/td><\/tr><tr><td>foo: \u2018bar\u2019<\/td><td><br><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Command ansible-playbook file.yaml Run an Ansible playbook called file.yaml Authentication options &#8211;user, -u &lt;username&gt; Log in as username &#8211;private-key, &#8211;key-file &lt;key&gt; Log in using SSH key (usually in ~\/.ssh) &#8211;ssh-extra-args Pass extra command options to SSH &#8211;vault-id &lt;id&gt; Use vault identity ID &#8211;vault-password-file &lt;key&gt; Use vault password file key &#8211;ask-vault-pass Prompt for a vault password [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-ansible"],"_links":{"self":[{"href":"https:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=103"}],"version-history":[{"count":1,"href":"https:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":104,"href":"https:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions\/104"}],"wp:attachment":[{"href":"https:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/triosdevelopers.com\/J.Smith\/rjeffsmith.ca\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}