Hi, I'm just starting with ansible.
I'm running a proxmox server with 12 containers.
I made some playbooks that actually works (like setting tzdata and apt-update)
I was trying to automate etc/hosts file update. I'm using this playbook, taken from
here:
---
- hosts: wordpress
gather_facts: True
tasks:
- name: update hosts
lineinfile: dest=/etc/hosts1 regexp='.*{{ item }}$' line="{{ hostvars[item].
ansible_default_ipv4.address }} {{item}}.mydomain {{item}} " state=present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['all']
Note I'm using
etc/hosts1 file and just 1 host for testing! When I get running will change to correct values.
This works, but duplicate lines every time I run playbook, like this:
192.168.0.30 wordpress.mydomain wordpress
192.168.0.30 wordpress.mydomain wordpress
192.168.0.30 wordpress.mydomain wordpress
Is there something I'm missing?
Thanks