Ja, Sie können. Mit jinja2 und group_vars.
Also, was Sie in Ihren Vorlagen tun/Ordner eine Datei wie eine solche erstellen:
templates/http.conf.j2
Sagen Sie so etwas wie dieses haben da drin:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName {{ subdomain }}.{{ domain }}
ServerAlias www.{{ subdomain }}.{{ domain }}
</VirtualHost>
Ihr Layout sollte wie folgt aussehen:
├── group_vars
│ ├── all
│ │ └── config
│ ├── dev
│ │ └── config
│ └── test
│ └── config
├── inventory
│ ├── dev
│ │ └── hosts
│ └── test
│ └── hosts
├── site.yml
└── templates
└── http.conf.j2
In group_vars/all
würden Sie haben domain: "example.com"
In group_vars/dev
würden Sie subdomain: dev
In group_vars/test
haben Sie subdomain: test
In Ihrer Aufgabe haben, würden Sie Ihre ansible Vorlage Befehl haben würde also
- hosts: all
tasks:
- name: Copy http conf
template:
dest: /etc/apache2/http.conf
src: templates/http.conf.j2
owner: root
group: root
Und Ihre Textbuch wie folgt ausführen :
ansible-playbook -i inventory/test site.yml
Die Datei sollte auf dem Host wie folgt aussehen:
<VirtualHost *:80>
ServerName test.example.com
ServerAlias www.test.example.com
</VirtualHost>