Bootstrap FreeKB - Ansible - module_defaults parameter
Ansible - module_defaults parameter

Updated:   |  Ansible articles

Let's say you are calling a module many times with similar parameters, like this.

---
- hosts: all
  tasks:
    - name: copy foo.txt
      copy:
        src: /tmp/foo.txt
        dest: /tmp/foo.txt
        owner: john.doe
        group: john.doe
        mode: "0644"

    - name: copy bar.txt
      copy:
        src: /tmp/bar.txt
        dest: /tmp/bar.txt
        owner: john.doe
        group: john.doe
        mode: "0644"

    - name: copy foobar.txt
      copy:
        src: /tmp/foobar.txt
        dest: /tmp/foobar.txt
        owner: john.doe
        group: john.doe
        mode: "0644"

 

The module_defaults parameter can be used to define default parameters for another module, like this.

---
- hosts: all
  module_defaults:
    copy:
        owner: john.doe
        group: john.doe
        mode: "0644"
  tasks:
    - name: copy foo.txt
      copy:
        src: /tmp/foo.txt
        dest: /tmp/foo.txt

    - name: copy bar.txt
      copy:
        src: /tmp/bar.txt
        dest: /tmp/bar.txt

    - name: copy foobar.txt
      copy:
        src: /tmp/foobar.txt
        dest: /tmp/foobar.txt

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 7a1fe4 in the box below so that we can be sure you are a human.