A
A
Anton2019-07-16 12:50:10
Ansible
Anton, 2019-07-16 12:50:10

How to write different variables to a file depending on the name of the application server?

There are 3 servers.
There is an application config.
How to write different variables to a file depending on the name of the application server?
Example
If {{ ansible_fqdn }} ends with app1dev.local, then you need to write dev-server.local in the config
If {{ ansible_fqdn }} ends with app1test.local, then you need to write tes-server.local in the config
If {{ ansible_fqdn }} ends with app1pre.local, then you need to write pre-server.local in the config.
I believe that you need 3 j2 templates and 3 blocks with different regexp_search:

- name: Template a file to /etc/sysconfig/config.conf
      template:
        src: config.conf.j2
        dest: etc/sysconfig/config.conf
        when: ansible_hostname | regexp_search("*.dev$")

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question