Skip to content

Instantly share code, notes, and snippets.

@psct
Created February 26, 2021 16:41
Show Gist options
  • Save psct/cbccbeeac6b4262abba367a2d990833e to your computer and use it in GitHub Desktop.
Save psct/cbccbeeac6b4262abba367a2d990833e to your computer and use it in GitHub Desktop.
Debian set hostname and adjust /etc/hosts
---
- name: set name, adjust /etc/hosts
hosts: all
become: yes
# order matters!
tasks:
- name: adjust /etc/hosts
replace:
path: /etc/hosts
regexp: '(\s*){{ ansible_hostname }}(\s*)'
replace: '\1{{ hostname }}\2'
- name: set hostname
hostname:
name: '{{ hostname }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment