Ansible - module_defaults parameter

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

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





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




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |