--- # Basic hostname setup - name: Get MAC address debug: msg="{{ hostvars[inventory_hostname].ansible_default_ipv4.macaddress }}" - name: store MAC address set_fact: my_macaddr: "{{ hostvars[inventory_hostname].ansible_default_ipv4.macaddress }}" - name: set hostname hostname: name={{ macaddrs[my_macaddr].hostname }} when: my_macaddr in macaddrs - name: update /etc/hosts with new hostname lineinfile: dest=/etc/hosts regexp="^{{ ansible_default_ipv4.address }}" line="{{ ansible_default_ipv4.address }}{{'\t'}}{{ macaddrs[my_macaddr].hostname }}.local{{'\t'}}{{ macaddrs[my_macaddr].hostname }}" state=present when: my_macaddr in macaddrs - name: get rid of default 127.0.1.1 binding lineinfile: dest=/etc/hosts regexp="^127.0.1.1" state=absent # Set timezone - name: set /etc/timezone copy: src=etc/timezone dest=/etc/timezone owner=root group=root mode=0644 backup=yes notify: - changed timezone # Other tasks - include: software.yml - include: users.yml - include: hardware.yml