Skip to content
Snippets Groups Projects
main.yml 1.56 KiB
Newer Older
- name: install hosts file
  copy: src=files/etcHosts dest=/etc/hosts owner=root mode=644
- name: get hostname by sysctl
  shell: sysctl kernel.hostname | cut -f 3 -d " "
  register: sysctl_hostname
  check_mode: no
- name: set hostname by sysctl
  shell: sysctl kernel.hostname="{{ inventory_hostname }}"
Chris Hines's avatar
Chris Hines committed
  when: not sysctl_hostname.stdout == inventory_hostname

- name: get domainname by sysctl
  shell: sysctl kernel.domainname | cut -f 3 -d " "
  register: sysctl_domainname
  check_mode: no
  become: true
  become_user: root

- name: set domainname by sysctl
  shell: sysctl kernel.domainname="{{ domain }}"
Chris Hines's avatar
Chris Hines committed
  when: not sysctl_domainname.stdout  ==  domain 

- name: set /etc/sysconfig/network on CentOS 6
  lineinfile: dest=/etc/sysconfig/network line='HOSTNAME={{ inventory_hostname }}' regexp='^HOSTNAME'
  when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"

- name: set /etc/sysctl.conf on Debian 8
  lineinfile: dest=/etc/sysctl.conf line='kernel.domainname = {{ domain }}' regexp='^#kernel.domainname'
  when: ansible_distribution == "Debian" and ansible_distribution_major_version == "8"

- name: set preserve hostname on CentOS
  lineinfile: 
  args:
    dest: /etc/cloud/cloud.cfg 
    line: "preserve_hostname: True"
  when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"

- name: set /etc/hostname
  template: src=hostname dest=/etc/hostname
  become: true
  become_user: root