O'Reilly logo

Ansible Configuration Management - Second Edition by Daniel Hall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding files with variables

All modules can take variables as part of their arguments by dereferencing them with {{ and }}. You can use this to load a particular file based on a variable. For example, you might want to select a different config file for NRPE (a Nagios check daemon) based on the architecture in use. Here is how that would look:

---
- name: Configure NRPE for the right architecture
  hosts: ansibletest
  user: root
  tasks:
    - name: Copy in the correct NRPE config file
      copy:
        src: "files/nrpe.{{ ansible_architecture }}.conf" dest: "/etc/nagios/nrpe.cfg"

In the copy and the template modules, you can also configure Ansible to look for a set of files, and it finds them using the first one. This lets you configure a file to look for; if that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required