%PDF- %PDF-
Direktori : /etc/ansible/roles/common/tasks/ |
Current File : //etc/ansible/roles/common/tasks/hostnames.yml |
--- # configure hostname on localhost # hostname var - name: set hostname on Centos6 shell: hostname {{ hostname }}; echo {{ hostname }} > /etc/hostname tags: hostname when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "6" - name: set hostname on Centos7 shell: hostnamectl set-hostname {{ hostname }} tags: hostname when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7" - name: set sysnetwork on host lineinfile: dest=/etc/sysconfig/network regexp="^\s*HOSTNAME=" line="HOSTNAME={{ hostname }}" tags: hostname # configure hosts file - name: remove temporary directory file: path=/tmp/hosts state=absent tags: hosts - name: create temporary directory file: path=/tmp/hosts state=directory tags: hosts - name: create a file which will holds current hosts records shell: mktemp /tmp/hosts/01_XXXXXX_hosts_current register: hosts_current_file tags: hosts - name: create a file which will holds pool hosts records shell: mktemp /tmp/hosts/02_XXXXXX_hosts_pool register: hosts_pool_file tags: hosts - name: create hosts file file: path: /etc/hosts state: touch - name: test localhost records shell: sed -n '/ANSIBLE MANAGED BLOCK/,+1!p' /etc/hosts | grep -v '^#\|^$' | grep -c 'localhost' ignore_errors: true tags: hosts register: localhost_test - name: add localhost record to hosts lineinfile: dest: /etc/hosts line: "{{ item }}" with_items: - '127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4' - '::1 localhost localhost.localdomain localhost6 localhost6.localdomain6' when: localhost_test.rc > 0 - name: get existen records from hosts file shell: sed -n '/ANSIBLE MANAGED BLOCK/,+1!p' /etc/hosts | grep -v '^#\|^$' > {{ hosts_current_file.stdout }} tags: hosts - name: create records for pool hosts template: src: hosts.j2 dest: "{{ hosts_pool_file.stdout }}" tags: hosts - name: assemble records for hosts file assemble: src=/tmp/hosts/ dest=/etc/hosts mode=0644 owner=root group=root tags: hosts # script which can ask master server for update ip address of client server in the ansible configuration - name: enable iflocal script on the server file: src={{ pool_replace_ifscript }} dest=/sbin/ifup-local state=link tags: hosts