{"id":7311,"date":"2018-04-06T08:47:31","date_gmt":"2018-04-06T00:47:31","guid":{"rendered":"http:\/\/rmohan.com\/?p=7311"},"modified":"2018-04-06T08:47:31","modified_gmt":"2018-04-06T00:47:31","slug":"ansible-summary","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7311","title":{"rendered":"Ansible summary"},"content":{"rendered":"<pre># An Ansible summary\r\n\r\n# Configuration file\r\n\r\n[intro\\<span class=\"skimlinks-unlinked\">_configuration.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/intro_configuration.html<\/span>)\r\n\r\nFirst one found from of\r\n\r\n* Contents of `$ANSIBLE_CONFIG`\r\n* `.\/<span class=\"skimlinks-unlinked\">ansible.cfg<\/span>`\r\n* `~\/.<span class=\"skimlinks-unlinked\">ansible.cfg<\/span>`\r\n* `\/etc\/ansible\/<span class=\"skimlinks-unlinked\">ansible.cfg<\/span>`\r\n\r\nConfiguration settings can be overridden by environment variables - see\r\n<span class=\"skimlinks-unlinked\">constants.py<\/span> in the source tree for names.\r\n\r\n# Patterns\r\n\r\n[intro\\<span class=\"skimlinks-unlinked\">_patterns.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/intro_patterns.html<\/span>)\r\n\r\nUsed on the `ansible` command line, or in playbooks.\r\n\r\n* `all` (or `*`)\r\n* hostname: `<span class=\"skimlinks-unlinked\">foo.example.com<\/span>`\r\n* groupname: `webservers`\r\n* or: `webservers:dbserver`\r\n* exclude: `webserver:!phoenix`\r\n* intersection: `webservers:&amp;staging`\r\n\r\nOperators can be chained: `webservers:dbservers:&amp;staging:!phoenix`\r\n\r\nPatterns can include variable substitutions: `{{foo}}`, wildcards:\r\n`*.<span class=\"skimlinks-unlinked\">example.com<\/span>` or 192.168.1.*, and regular expressions:\r\n`~(web|db).*\\.example\\.com`\r\n\r\n# Inventory files\r\n\r\n[intro\\<span class=\"skimlinks-unlinked\">_inventory.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/intro_inventory.html<\/span>),\r\n[intro\\_dynamic\\<span class=\"skimlinks-unlinked\">_inventory.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/intro_dynamic_inventory.html<\/span>)\r\n\r\n'INI-file' structure, blocks define groups. Hosts allowed in more than\r\none group. Non-standard SSH port can follow hostname separated by ':'\r\n(but see also `ansible_ssh_port` below).\r\n\r\nHostname ranges: `www[01:50].<span class=\"skimlinks-unlinked\">example.com<\/span>`, `db-[a:f].<span class=\"skimlinks-unlinked\">example.com<\/span>`\r\n\r\nPer-host variables: `<span class=\"skimlinks-unlinked\">foo.example.com<\/span> foo=bar baz=wibble`\r\n\r\n* `[foo:children]`: new group `foo` containing all members if included groups\r\n* `[foo:vars]`: variable definitions for all members of group `foo`\r\n\r\nInventory file defaults to `\/etc\/ansible\/hosts`. Veritable with `-i`\r\nor in the configuration file. The 'file' can also be a dynamic\r\ninventory script. If a directory, all contained files are processed.\r\n\r\n# Variable files: \r\n\r\n[intro\\<span class=\"skimlinks-unlinked\">_inventory.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/intro_inventory.html<\/span>)\r\n\r\nYAML; given inventory file at `.\/hosts`:\r\n\r\n* `.\/group_vars\/foo`: variable definitions for all members of group `foo`\r\n* `.\/host_vars\/<span class=\"skimlinks-unlinked\">foo.example.com<\/span>`: variable definitions for <span class=\"skimlinks-unlinked\">foo.example.com<\/span>\r\n\r\n`group_vars` and `host_vars` directories can also exist in the playbook\r\ndirectory. If both paths exist, variables in the playbook directory\r\nwill be loaded second. \r\n\r\n# Behavioral inventory parameters:\r\n\r\n[intro\\<span class=\"skimlinks-unlinked\">_inventory.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/intro_inventory.html<\/span>)\r\n\r\n* `ansible_ssh_host`\r\n* `ansible_ssh_port`\r\n* `ansible_ssh_user`\r\n* `ansible_ssh_pass`\r\n* `ansible_sudo_pass`\r\n* `ansible_connection`\r\n* `ansible_ssh_private_key_file`\r\n* `ansible_python_interpreter`\r\n* `ansible_*_interpreter`\r\n\r\n# Playbooks\r\n\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_intro.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_intro.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_roles.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_roles.html<\/span>)\r\n\r\nPlaybooks are a YAML list of one or more plays. Most (all?) keys are\r\noptional. Lines can be broken on space with continuation lines\r\nindented.\r\n\r\nPlaybooks consist of a list of one or more 'plays' and\/or inclusions:\r\n\r\n    ---\r\n    - include: <span class=\"skimlinks-unlinked\">playbook.yml<\/span>\r\n    - &lt;play&gt;\r\n    - ...\r\n\r\n## Plays\r\n\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_intro.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_intro.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_roles.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_roles.htm<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_variables.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_variables.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_conditionals.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_conditionals.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_acceleration.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_acceleration.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_delegation.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_delegation.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_prompts.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_prompts.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_tags.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_tags.htm<\/span>)\r\n[Forum posting](<span class=\"skimlinks-unlinked\">https:\/\/groups.google.com\/forum\/#!topic\/ansible-project\/F9mIAfo6orc<\/span>)\r\n[Forum postinb](<span class=\"skimlinks-unlinked\">https:\/\/groups.google.com\/forum\/#!topic\/Ansible-project\/MU_ws7zynnI<\/span>)\r\n    \r\nPlays consist of play metadata and a sequence of task and handler\r\ndefinitions, and roles.\r\n\r\n    - hosts: webservers\r\n      remote_user: root\r\n      sudo: yes\r\n      sudo_user: postgress\r\n      su: yes\r\n      su_user: exim\r\n      gather_facts: no\r\n      accelerate: no\r\n      accelerate_port: 5099\r\n      any_errors_fatal: yes\r\n      max_fail_percentage: 30\r\n      connection: local\r\n      serial: 5\r\n      vars:\r\n        http_port: 80\r\n      vars_files:\r\n        - \"<span class=\"skimlinks-unlinked\">vars.yml<\/span>\"\r\n        - [ \"<span class=\"skimlinks-unlinked\">try-first.yml<\/span>\", \"<span class=\"skimlinks-unlinked\">try-second-.yml<\/span>\" ]\r\n      vars_prompt:\r\n        - name: \"my_password2\"\r\n          prompt: \"Enter password2\"\r\n          default: \"secret\"\r\n          private: yes\r\n          encrypt: \"md5_crypt\"\r\n          confirm: yes\r\n          salt: 1234\r\n          salt_size: 8\r\n      tags: \r\n        - stuff\r\n        - nonsence\r\n      pre_tasks:\r\n        - &lt;task&gt;\r\n        - ...\r\n      roles:\r\n        - common\r\n        - { role: common, port: 5000, when: \"bar == 'Baz'\", tags :[one, two] }\r\n        - { role: common, when: month == 'Jan' }\r\n        - ...\r\n      tasks:\r\n        - include: <span class=\"skimlinks-unlinked\">tasks.yaml<\/span>\r\n        - include: <span class=\"skimlinks-unlinked\">tasks.yaml<\/span> foo=bar baz=wibble\r\n        - include: <span class=\"skimlinks-unlinked\">tasks.yaml<\/span>\r\n          vars:\r\n            foo: aaa \r\n            baz:\r\n              - z\r\n              - y\r\n        - { include: <span class=\"skimlinks-unlinked\">tasks.yaml<\/span>, foo: zzz, baz: [a,b]}\r\n        - include: <span class=\"skimlinks-unlinked\">tasks.yaml<\/span>\r\n          when: day == 'Thursday'\r\n        - &lt;task&gt;\r\n        - ...\r\n      post_tasks:\r\n        - &lt;task&gt;\r\n        - ...\r\n      handlers:\r\n        - include: <span class=\"skimlinks-unlinked\">handlers.yml<\/span>\r\n        - &lt;task&gt;\r\n        - ...\r\n\r\nUsing `encrypt` with `vars_prompt` requires that\r\n[Passlib](<span class=\"skimlinks-unlinked\">http:\/\/pythonhosted.org\/passlib<\/span>\/) is installed.\r\n\r\nIn addition the source code implies the availability of the following\r\nwhich don't *seem* to be mentioned in the documentation: `name`, `user` (deprecated), `port`, `accelerate_ipv6`, `role_names`, and `vault_password`.\r\n\r\n## Task definitions\r\n\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_intro.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_intro.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_roles.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_roles.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_async.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_async.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_checkmode.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com<\/span>\/[<span class=\"skimlinks-unlinked\">playbooks_checkmode.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_delegation.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_delegation.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_environment.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_environment.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_error_handling.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_error_handling.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_tags.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_tags.html<\/span>)\r\n[ansible-1-5-released](<span class=\"skimlinks-unlinked\">http:\/\/www.ansible.com\/blog\/2014\/02\/28\/ansible-1-5-released<\/span>)\r\n[Forum posting](<span class=\"skimlinks-unlinked\">https:\/\/groups.google.com\/forum\/#!topic\/ansible-project\/F9mIAfo6orc<\/span>)\r\n[Ansible examples](<span class=\"skimlinks-unlinked\">https:\/\/github.com\/ansible\/ansible-examples\/blob\/master\/language_features\/complex_args.yml<\/span>)\r\n\r\nEach task definition is a list of items, normally including at least a\r\nname and a module invocation:\r\n\r\n    - name: task\r\n      remote_user: apache\r\n      sudo: yes\r\n      sudo_user: postgress\r\n      sudo_pass: wibble\r\n      su: yes\r\n      su_user: exim\r\n      ignore_errors: True\r\n      delegate_to: 127.0.0.1\r\n      async: 45\r\n      poll: 5\r\n      always_run: no\r\n      run_once: false\r\n      meta: flush_handlers\r\n      no_log: true\r\n      environment: &lt;hash&gt;\r\n      environment:\r\n        var1: val1\r\n        var2: val2\r\n      tags: \r\n        - stuff\r\n        - nonsence\r\n      &lt;module&gt;: src=<span class=\"skimlinks-unlinked\">template.j2<\/span> dest=\/etc\/<span class=\"skimlinks-unlinked\">foo.conf<\/span>\r\n      action: &lt;module&gt;, src=<span class=\"skimlinks-unlinked\">template.j2<\/span> dest=\/etc\/<span class=\"skimlinks-unlinked\">foo.conf<\/span>\r\n      action: &lt;module&gt;\r\n      args:\r\n          src=<span class=\"skimlinks-unlinked\">template.j2<\/span>\r\n          dest=\/etc\/<span class=\"skimlinks-unlinked\">foo.conf<\/span>\r\n      local_action: &lt;module&gt; \/usr\/bin\/take_out_of_pool {{ inventory_hostname }}\r\n      when: ansible_os_family == \"Debian\"\r\n      register: result\r\n      failed_when: \"'FAILED' in result.stderr\"\r\n      changed_when: <span class=\"skimlinks-unlinked\">result.rc<\/span> != 2\r\n      notify:\r\n        - restart apache\r\n\r\n`delegate_to: 127.0.0.1` is implied by `local_action:`\r\n\r\nThe forms `&lt;module&gt;: &lt;args&gt;`, `action: &lt;module&gt; &lt;args&gt;`, and `local_action: &lt;module&gt; &lt;args&gt;` are mutually-exclusive. \r\n\r\nAdditional keys `when_*`, `until`, `retries` and `delay` are documented below under 'Loops'.\r\n\r\nIn addition the source code implies the availability of the following\r\nwhich don't *seem* to be mentioned in the documentation: \r\n`first_available_file` (deprecated), `transport`, \r\n`connection`, `any_errors_fatal`.\r\n\r\n# Roles\r\n\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_roles.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_roles.html<\/span>)\r\n\r\nDirectory structure:\r\n\r\n    <span class=\"skimlinks-unlinked\">playbook.yml<\/span>\r\n    roles\/\r\n       common\/\r\n         tasks\/\r\n           <span class=\"skimlinks-unlinked\">main.yml<\/span>\r\n         handlers\/\r\n           <span class=\"skimlinks-unlinked\">main.yml<\/span>\r\n         vars\/\r\n           <span class=\"skimlinks-unlinked\">main.yml<\/span>\r\n         meta\/\r\n           <span class=\"skimlinks-unlinked\">main.yml<\/span>\r\n         defaults\/\r\n           <span class=\"skimlinks-unlinked\">main.yml<\/span>\r\n         files\/\r\n         templates\/\r\n         library\/\r\n\r\n# Modules\r\n\r\n[<span class=\"skimlinks-unlinked\">modules.htm<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/modules.htm<\/span>),\r\n[modules\\_by\\<span class=\"skimlinks-unlinked\">_category.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/modules_by_category.html<\/span>)\r\n\r\nList all installed modules with\r\n\r\n    ansible-doc --list\r\n\r\nDocument a particular module with\r\n\r\n    ansible-doc &lt;module&gt;\r\n\r\nShow playbook snippet for specified module\r\n\r\n    ansible-doc -i &lt;module&gt;\r\n\r\n# Variables\r\n\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_roles.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_roles.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_variables.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_variables.html<\/span>)\r\n\r\nNames: letters, digits, underscores; starting with a letter.\r\n\r\n## Substitution examples: \r\n\r\n* `{{ var }}`\r\n* `{{ var[\"key1\"][\"key2\"]}}`\r\n* `{{ <span class=\"skimlinks-unlinked\">var.key1.key2<\/span> }}`\r\n* `{{ list[0] }}`\r\n\r\nYAML requires an item starting with a variable substitution to be quoted.\r\n\r\n## Sources: \r\n\r\n* Highest priority:\r\n    * `--extra-vars` on the command line\r\n* General:\r\n    * `vars` component of a playbook\r\n    * From files referenced by `vars_file` in a playbook\r\n    * From included files (incl. roles)\r\n    * Parameters passed to includes\r\n    * `register:` in tasks\r\n* Lower priority:\r\n    * Inventory (set on host or group)\r\n* Lower priority:\r\n    * Facts (see below)\r\n    * Any `\/etc\/ansible\/facts.d\/<span class=\"skimlinks-unlinked\">filename.fact<\/span>` on managed machines \r\n      (sets variables with `ansible_local.filename. prefix)\r\n* Lowest priority\r\n    * Role defaults (from defaults\/<span class=\"skimlinks-unlinked\">main.yml<\/span>)\r\n\r\n## Built-in:\r\n\r\n* `hostvars` (e.g. `hostvars[<span class=\"skimlinks-unlinked\">other.example.com<\/span>][...]`)\r\n* `group_names` (groups containing current host)\r\n* `groups` (all groups and hosts in the inventory)\r\n* `inventory_hostname` (current host as in inventory)\r\n* `inventory_hostname_short` (first component of inventory_hostname)\r\n* `play_hosts` (hostnames in scope for current play)\r\n* `inventory_dir` (location of the inventory)\r\n* `inventoty_file` (name of the inventory)\r\n\r\n## Facts:\r\n\r\nRun `ansible hostname -m setup`, but in particular:\r\n\r\n* `ansible_distribution`\r\n* `ansible_distribution_release`\r\n* `ansible_distribution_version`\r\n* `ansible_fqdn`\r\n* `ansible_hostname`\r\n* `ansible_os_family`\r\n* `ansible_pkg_mgr`\r\n* `ansible_default_ipv4.address`\r\n* `ansible_default_ipv6.address`\r\n\r\n## Content of 'registered' variables:\r\n\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_conditionals.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_conditionals.html<\/span>),\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_loops.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_loops.html<\/span>)\r\n\r\nDepends on module. Typically includes:\r\n\r\n* `.rc`\r\n* `.stdout`\r\n* `.stdout_lines`\r\n* `.changed`\r\n* `.msg` (following failure)\r\n* `.results` (when used in a loop)\r\n\r\nSee also `failed`, `changed`, etc filters.\r\n\r\nWhen used in a loop the `result` element is a list containing all\r\nresponses from the module.\r\n\r\n## Additionally available in templates:\r\n\r\n* `ansible_managed`: string containing the information below\r\n* `template_host`: node name of the template\u00e2??s machine\r\n* `template_uid`: the owner\r\n* `template_path`: absolute path of the template\r\n* `template_fullpath`: the absolute path of the template\r\n* `template_run_date`: the date that the template was rendered\r\n\r\n# Filters\r\n\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_variables.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_variables.html<\/span>)\r\n\r\n* `{{ var | to_nice_json }}`\r\n* `{{ var | to_json }}`\r\n* `{{ var | from_json }}`\r\n* `{{ var | to_nice_yml }}`\r\n* `{{ var | to_yml }}`\r\n* `{{ var | from_yml }}`\r\n* `{{ result | failed }}`\r\n* `{{ result | changed }}`\r\n* `{{ result | success }}`\r\n* `{{ result | skipped }}`\r\n* `{{ var | manditory }}`\r\n* `{{ var | default(5) }}`\r\n* `{{ list1 | unique }}`\r\n* `{{ list1 | union(list2) }}`\r\n* `{{ list1 | intersect(list2) }}`\r\n* `{{ list1 | difference(list2) }}`\r\n* `{{ list1 | symmetric_difference(list2) }}`\r\n* `{{ ver1 | version_compare(ver2, operator='&gt;=', strict=True }}`\r\n* `{{ list | random }}`\r\n* `{{ number | random }}`\r\n* `{{ number | random(start=1, step=10) }}`\r\n* `{{ list | join(\" \") }}`\r\n* `{{ path | basename }}`\r\n* `{{ path | dirname }}`\r\n* `{{ path | expanduser }}`\r\n* `{{ path | realpath }}`\r\n* `{{ var | b64decode }}`\r\n* `{{ var | b64encode }}`\r\n* `{{ filename | md5 }}`\r\n* `{{ var | bool }}`\r\n* `{{ var | int }}`\r\n* `{{ var | quote }}`\r\n* `{{ var | md5 }}`\r\n* `{{ var | fileglob }}`\r\n* `{{ var | match }}`\r\n* `{{ var | search }}`\r\n* `{{ var | regex }}`\r\n* `{{ var | regexp_replace('from', 'to' )}}`\r\n\r\nSee also [default jinja2\r\nfilters](<span class=\"skimlinks-unlinked\">http:\/\/jinja.pocoo.org\/docs\/templates\/#builtin-filters<\/span>). In\r\nYAML, values starting `{` must be quoted.\r\n\r\n# Lookups\r\n\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_lookups.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_lookups.html<\/span>)\r\n\r\nLookups are evaluated on the control machine. \r\n\r\n* `{{ lookup('file', '\/etc\/<span class=\"skimlinks-unlinked\">foo.txt<\/span>') }}`\r\n* `{{ lookup('password', '\/tmp\/passwordfile length=20 chars=ascii_letters,digits') }}`\r\n* `{{ lookup('env','HOME') }}`\r\n* `{{ lookup('pipe','date') }}`\r\n* `{{ lookup('redis_kv', 'redis:\/\/localhost:6379,somekey') }}`\r\n* `{{ lookup('dnstxt', '<span class=\"skimlinks-unlinked\">example.com<\/span>') }}`\r\n* `{{ lookup('template', '.\/<span class=\"skimlinks-unlinked\">some_template.j2<\/span>') }}`\r\n\r\nLookups can be assigned to variables and will be evaluated each time\r\nthe variable is used.\r\n\r\nLookup plugins also support loop iteration (see below).\r\n\r\n# Conditions\r\n\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_conditionals.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_conditionals.html<\/span>)\r\n\r\n`when: &lt;condition&gt;`, where condition is:\r\n\r\n* `var == \"Vaue\"`, `var &gt;= 5`, etc.\r\n* `var`, where `var` coreces to boolean (yes, true, True, TRUE)\r\n* `var is defined`, `var is not defined`\r\n* `&lt;condition1&gt; and &lt;condition2&gt;` (also `or`?)\r\n\r\nCombined with `with_items`, the when statement is processed for each item.\r\n\r\n`when` can also be applied to includes and roles. Conditional Imports\r\nand variable substitution in file and template names can avoid the\r\nneed for explicit conditionals.\r\n\r\n# Loops\r\n\r\n[playbooks\\<span class=\"skimlinks-unlinked\">_loops.html<\/span>](<span class=\"skimlinks-unlinked\">http:\/\/docs.ansible.com\/playbooks_loops.html<\/span>)\r\n\r\nIn addition the source code implies the availability of the following\r\nwhich don't *seem* to be mentioned in the documentation: `csvfile`, `etcd`, `inventory_hostname`. \r\n\r\n## Standard:\r\n\r\n    - user: name={{ item }} state=present groups=wheel\r\n      with_items:\r\n        - testuser1\r\n        - testuser2\r\n       \r\n    - name: add several users\r\n      user: name={{ <span class=\"skimlinks-unlinked\">item.name<\/span> }} state=present groups={{ item.groups }}\r\n      with_items:\r\n        - { name: 'testuser1', groups: 'wheel' }\r\n        - { name: 'testuser2', groups: 'root' }\r\n\r\n      with_items: somelist\r\n    \r\n## Nested:\r\n\r\n    - mysql_user: name={{ item[0] }} priv={{ item[1] }}.*:ALL                \r\n                               append_privs=yes password=foo\r\n      with_nested:\r\n        - [ 'alice', 'bob', 'eve' ]\r\n        - [ 'clientdb', 'employeedb', 'providerdb' ]\r\n        \r\n## Over hashes:\r\n\r\nGiven\r\n\r\n    ---\r\n    users:\r\n      alice:\r\n        name: Alice Appleworth\r\n        telephone: 123-456-7890\r\n      bob:\r\n        name: Bob Bananarama\r\n        telephone: 987-654-3210\r\n        \r\n    tasks:\r\n      - name: Print phone records\r\n        debug: msg=\"User {{ <span class=\"skimlinks-unlinked\">item.key<\/span> }} is {{ <span class=\"skimlinks-unlinked\">item.value.name<\/span> }} \r\n                         ({{ <span class=\"skimlinks-unlinked\">item.value.telephone<\/span> }})\"\r\n        with_dict: users\r\n\r\n## Fileglob:\r\n\r\n    - copy: src={{ item }} dest=\/etc\/fooapp\/ owner=root mode=600\r\n      with_fileglob:\r\n        - \/playbooks\/files\/fooapp\/*\r\n\r\nIn a role, relative paths resolve relative to the\r\n`roles\/&lt;rolename&gt;\/files` directory.\r\n\r\n## With content of file:\r\n\r\n(see example for `authorized_key` module)\r\n\r\n    - authorized_key: user=deploy key=\"{{ item }}\"\r\n      with_file:\r\n        - public_keys\/doe-jane\r\n        - public_keys\/doe-john\r\n\r\nSee also the `file` lookup when the content of a file is needed.\r\n\r\n## Parallel sets of data:\r\n\r\nGiven\r\n\r\n    ---\r\n    alpha: [ 'a', 'b', 'c', 'd' ]\r\n    numbers:  [ 1, 2, 3, 4 ]\r\n    \r\n    - debug: msg=\"{{ item.0 }} and {{ item.1 }}\"\r\n      with_together:\r\n        - alpha\r\n        - numbers\r\n\r\n## Subelements:\r\n\r\nGiven\r\n\r\n    ---\r\n    users:\r\n      - name: alice\r\n        authorized:\r\n          - \/tmp\/alice\/<span class=\"skimlinks-unlinked\">onekey.pub<\/span>\r\n          - \/tmp\/alice\/<span class=\"skimlinks-unlinked\">twokey.pub<\/span>\r\n      - name: bob\r\n        authorized:\r\n          - \/tmp\/bob\/<span class=\"skimlinks-unlinked\">id_rsa.pub<\/span>\r\n    \r\n    - authorized_key: \"user={{ item.0.name }} \r\n                       key='{{ lookup('file', item.1) }}'\"\r\n      with_subelements:\r\n         - users\r\n         - authorized\r\n         \r\n## Integer sequence:\r\n\r\nDecimal, hexadecimal (0x3f8) or octal (0600)\r\n\r\n    - user: name={{ item }} state=present groups=evens\r\n      with_sequence: start=0 end=32 format=testuser%02x\r\n          \r\n      with_sequence: start=4 end=16 stride=2\r\n          \r\n      with_sequence: count=4\r\n          \r\n## Random choice:\r\n\r\n    - debug: msg={{ item }}\r\n      with_random_choice:\r\n         - \"go through the door\"\r\n         - \"drink from the goblet\"\r\n         - \"press the red button\"\r\n         - \"do nothing\"\r\n         \r\n## Do-Until:\r\n\r\n    - action: shell \/usr\/bin\/foo\r\n      register: result\r\n      until: <span class=\"skimlinks-unlinked\">result.stdout.find(\"all<\/span>ems go\") != -1\r\n      retries: 5\r\n      delay: 10\r\n\r\n## Results of a local program:\r\n\r\n    - name: Example of looping over a command result\r\n      shell: \/usr\/bin\/frobnicate {{ item }}\r\n      with_lines: \/usr\/bin\/frobnications_per_host \r\n                           --param {{ inventory_hostname }}\r\n                           \r\nTo loop over the results of a remote program, use `register: result`\r\nand then `with_items: result.stdout_lines` in a subsequent\r\ntask.\r\n                           \r\n## Indexed list:\r\n\r\n    - name: indexed loop demo\r\n      debug: msg=\"at array position {{ item.0 }} there is \r\n                                         a value {{ item.1 }}\"\r\n      with_indexed_items: some_list\r\n      \r\n## Flattened list:\r\n\r\n    ---\r\n    # file: roles\/foo\/vars\/<span class=\"skimlinks-unlinked\">main.yml<\/span>\r\n    packages_base:\r\n      - [ 'foo-package', 'bar-package' ]\r\n    packages_apps:\r\n      - [ ['one-package', 'two-package' ]]\r\n      - [ ['red-package'], ['blue-package']]\r\n      \r\n    - name: flattened loop demo\r\n      yum: name={{ item }} state=installed\r\n      with_flattened:\r\n        - packages_base\r\n        - packages_apps      \r\n\r\n## First found:\r\n\r\n    - name: template a file\r\n      template: src={{ item }} dest=\/etc\/myapp\/<span class=\"skimlinks-unlinked\">foo.conf<\/span>\r\n      with_first_found:\r\n        - files:\r\n            - {{ ansible_distribution }}.conf\r\n            - <span class=\"skimlinks-unlinked\">default.conf<\/span>\r\n          paths:\r\n             - search_location_one\/somedir\/\r\n             - \/opt\/other_location\/somedir\/\r\n            \r\n# Tags\r\n\r\nBoth plays and tasks support a `tags:` attribute.\r\n\r\n    - template: src=templates\/<span class=\"skimlinks-unlinked\">src.j2<\/span> dest=\/etc\/<span class=\"skimlinks-unlinked\">foo.conf<\/span>\r\n      tags:\r\n        - configuration\r\n\r\nTags can be applied to roles and includes (effectively tagging all\r\nincluded tasks)\r\n         \r\n    roles:\r\n        - { role: webserver, port: 5000, tags: [ 'web', 'foo' ] }\r\n\r\n    - include: <span class=\"skimlinks-unlinked\">foo.yml<\/span> tags=web,foo\r\n    \r\nTo select by tag:\r\n\r\n    ansible-playbook <span class=\"skimlinks-unlinked\">example.yml<\/span> --tags \"configuration,packages\"\r\n    ansible-playbook <span class=\"skimlinks-unlinked\">example.yml<\/span> --skip-tags \"notification\"\r\n\r\n# Command lines\r\n\r\n## ansible\r\n\r\n    Usage: ansible &lt;host-pattern&gt; [options]\r\n\r\n    Options:\r\n      -a MODULE_ARGS, --args=MODULE_ARGS\r\n                            module arguments\r\n      -k, --ask-pass        ask for SSH password\r\n      --ask-su-pass         ask for su password\r\n      -K, --ask-sudo-pass   ask for sudo password\r\n      --ask-vault-pass      ask for vault password\r\n      -B SECONDS, --background=SECONDS\r\n                            run asynchronously, failing after X seconds\r\n                            (default=N\/A)\r\n      -C, --check           don't make any changes; instead, try to predict some\r\n                            of the changes that may occur\r\n      -c CONNECTION, --connection=CONNECTION\r\n                            connection type to use (default=smart)\r\n      -f FORKS, --forks=FORKS\r\n                            specify number of parallel processes to use\r\n                            (default=5)\r\n      -h, --help            show this help message and exit\r\n      -i INVENTORY, --inventory-file=INVENTORY\r\n                            specify inventory host file\r\n                            (default=\/etc\/ansible\/hosts)\r\n      -l SUBSET, --limit=SUBSET\r\n                            further limit selected hosts to an additional pattern\r\n      --list-hosts          outputs a list of matching hosts; does not execute\r\n                            anything else\r\n      -m MODULE_NAME, --module-name=MODULE_NAME\r\n                            module name to execute (default=command)\r\n      -M MODULE_PATH, --module-path=MODULE_PATH\r\n                            specify path(s) to module library\r\n                            (default=\/usr\/share\/ansible)\r\n      -o, --one-line        condense output\r\n      -P POLL_INTERVAL, --poll=POLL_INTERVAL\r\n                            set the poll interval if using -B (default=15)\r\n      --private-key=PRIVATE_KEY_FILE\r\n                            use this file to authenticate the connection\r\n      -S, --su              run operations with su\r\n      -R SU_USER, --su-user=SU_USER\r\n                            run operations with su as this user (default=root)\r\n      -s, --sudo            run operations with sudo (nopasswd)\r\n      -U SUDO_USER, --sudo-user=SUDO_USER\r\n                            desired sudo user (default=root)\r\n      -T TIMEOUT, --timeout=TIMEOUT\r\n                            override the SSH timeout in seconds (default=10)\r\n      -t TREE, --tree=TREE  log output to this directory\r\n      -u REMOTE_USER, --user=REMOTE_USER\r\n                            connect as this user (default=jw35)\r\n      --vault-password-file=VAULT_PASSWORD_FILE\r\n                            vault password file\r\n      -v, --verbose         verbose mode (-vvv for more, -vvvv to enable\r\n                            connection debugging)\r\n      --version             show program's version number and exit\r\n\r\n##  ansible-playbook\r\n\r\n    Usage: ansible-playbook <span class=\"skimlinks-unlinked\">playbook.yml<\/span>\r\n\r\n    Options:\r\n      -k, --ask-pass        ask for SSH password\r\n      --ask-su-pass         ask for su password\r\n      -K, --ask-sudo-pass   ask for sudo password\r\n      --ask-vault-pass      ask for vault password\r\n      -C, --check           don't make any changes; instead, try to predict some\r\n                            of the changes that may occur\r\n      -c CONNECTION, --connection=CONNECTION\r\n                            connection type to use (default=smart)\r\n      -D, --diff            when changing (small) files and templates, show the\r\n                            differences in those files; works great with --check\r\n      -e EXTRA_VARS, --extra-vars=EXTRA_VARS\r\n                            set additional variables as key=value or YAML\/JSON\r\n      -f FORKS, --forks=FORKS\r\n                            specify number of parallel processes to use\r\n                            (default=5)\r\n      -h, --help            show this help message and exit\r\n      -i INVENTORY, --inventory-file=INVENTORY\r\n                            specify inventory host file\r\n                            (default=\/etc\/ansible\/hosts)\r\n      -l SUBSET, --limit=SUBSET\r\n                            further limit selected hosts to an additional pattern\r\n      --list-hosts          outputs a list of matching hosts; does not execute\r\n                            anything else\r\n      --list-tasks          list all tasks that would be executed\r\n      -M MODULE_PATH, --module-path=MODULE_PATH\r\n                            specify path(s) to module library\r\n                            (default=\/usr\/share\/ansible)\r\n      --private-key=PRIVATE_KEY_FILE\r\n                            use this file to authenticate the connection\r\n      --skip-tags=SKIP_TAGS\r\n                            only run plays and tasks whose tags do not match these\r\n                            values\r\n      --start-at-task=START_AT\r\n                            start the playbook at the task matching this name\r\n      --step                one-step-at-a-time: confirm each task before running\r\n      -S, --su              run operations with su\r\n      -R SU_USER, --su-user=SU_USER\r\n                            run operations with su as this user (default=root)\r\n      -s, --sudo            run operations with sudo (nopasswd)\r\n      -U SUDO_USER, --sudo-user=SUDO_USER\r\n                            desired sudo user (default=root)\r\n      --syntax-check        perform a syntax check on the playbook, but do not\r\n                            execute it\r\n      -t TAGS, --tags=TAGS  only run plays and tasks tagged with these values\r\n      -T TIMEOUT, --timeout=TIMEOUT\r\n                            override the SSH timeout in seconds (default=10)\r\n      -u REMOTE_USER, --user=REMOTE_USER\r\n                            connect as this user (default=jw35)\r\n      --vault-password-file=VAULT_PASSWORD_FILE\r\n                            vault password file\r\n      -v, --verbose         verbose mode (-vvv for more, -vvvv to enable\r\n                            connection debugging)\r\n      --version             show program's version number and exit\r\n\r\n## ansible-vault\r\n\r\n\r\n<span class=\"skimlinks-unlinked\">playbooks_vault.html<\/span>\r\n\r\n    Usage: ansible-vault [create|decrypt|edit|encrypt|rekey] [--help] [options] file_name\r\n\r\n    Options:\r\n      -h, --help  show this help message and exit\r\n\r\n    See 'ansible-vault &lt;command&gt; --help' for more information on a specific command.\r\n\r\n## ansible-doc\r\n\r\n    Usage: ansible-doc [options] [module...]\r\n\r\n    Show Ansible module documentation\r\n\r\n    Options:\r\n      --version             show program's version number and exit\r\n      -h, --help            show this help message and exit\r\n      -M MODULE_PATH, --module-path=MODULE_PATH\r\n                                 Ansible modules\/ directory\r\n      -l, --list            List available modules\r\n      -s, --snippet         Show playbook snippet for specified module(s)\r\n      -v                    Show version number and exit\r\n   \r\n## ansible-galaxy\r\n\r\n    Usage: ansible-galaxy [init|info|install|list|remove] [--help] [options] ...\r\n\r\n    Options:\r\n      -h, --help  show this help message and exit\r\n\r\n      See 'ansible-galaxy &lt;command&gt; --help' for more information on a\r\n      specific command \r\n\r\n## ansible-pull\r\n\r\n    Usage: ansible-pull [options] [<span class=\"skimlinks-unlinked\">playbook.yml<\/span>]\r\n\r\n    ansible-pull: error: URL for repository not specified, use -h for help<\/pre>\n","protected":false},"excerpt":{"rendered":"<p># An Ansible summary # Configuration file [intro\\_configuration.html](http:\/\/docs.ansible.com\/intro_configuration.html) First one found from of * Contents of `$ANSIBLE_CONFIG` * `.\/ansible.cfg` * `~\/.ansible.cfg` * `\/etc\/ansible\/ansible.cfg` Configuration settings can be overridden by environment variables &#8211; see constants.py in the source tree for names. # Patterns [intro\\_patterns.html](http:\/\/docs.ansible.com\/intro_patterns.html) Used on the `ansible` command line, or in playbooks. * `all` (or [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7311"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7311"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7311\/revisions"}],"predecessor-version":[{"id":7312,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7311\/revisions\/7312"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}