1
---
- hosts: webserver
  become: true
  tasks:
    - name: install web components
      apt: name={{item}} state=present update_cache=yes
      with_items:
        - apache2
    - name: copy apache virtual hosts config
      copy: src=demo/demo.conf dest=/etc/apache2/sites-available mode=0755
      notify: restart apache2

I'm trying to, on copying demo.conf to the first host, rename as demo1.conf and on copying to second host it should be rename as demo2.conf and so on.

Or can it be renamed as demo{hostname}.conf?

What are some insights on this particular use case?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

1

Modify your copy line like this:

copy: src=demo/demo.conf dest=/etc/apache2/sites-available/demo{{inventory_hostname}}.conf mode=0755

And you will have your destination file name linked with the name of the hostname.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Frenchy
  • 16,386
  • 3
  • 16
  • 39