--- - name: "create file: /etc/hostname" copy: content: "{{system.hostname}}" dest: /etc/hostname register: hostnameFile when: system.hostname is defined - name: Change hostname of running system hostname: name: "{{system.hostname}}" when: - system.hostname is defined - hostnameFile.changed - name: "create file: /etc/hosts" template: src: hosts.conf.j2 dest: /etc/hosts mode: 0755 when: system.hostname is defined - name: "create file: /etc/resolv.conf" template: src: resolv.conf.j2 dest: /etc/resolv.conf mode: 0755 when: system.nameservers is defined