Mastering Ansible by James Freeman

Mastering Ansible by James Freeman

Author:James Freeman
Language: eng
Format: epub
Tags: COM051360 - COMPUTERS / Programming Languages / Python, COM051440 - COMPUTERS / Software Development and Engineering / Tools, COM088010 - COMPUTERS / System Administration / Linux and UNIX Administration
Publisher: Packt Publishing
Published: 2019-03-22T12:28:51+00:00


tasks:

- name: create a directory

file:

path: /srv/whiskey/alpha

state: directory

- name: create another directory

file:

path: /srv/whiskey/beta

state: directory

When we run this, as expected, our two directories get created:

However, you can see this code is repetitive and inefficient. Instead, we could change it to something like this:

---

- name: looping demo

hosts: localhost

gather_facts: false

tasks:

- name: create a directory

file:

path: "{{ item }}"

state: directory

loop:

- /srv/whiskey/alpha

- /srv/whiskey/beta

Note the use of the special variable item, which is now used to define the path from the loop items at the bottom of the task. Now, when we run this code, the output looks somewhat different:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.