|
@@ -69,19 +69,19 @@
|
|
|
command: grep "{{ inventory_hostname }}" ../../provision/files/new_mapping_file.csv
|
|
|
delegate_to: localhost
|
|
|
register: file_present
|
|
|
- when: mapping_file == "true"
|
|
|
+ when: mapping_file | bool == true
|
|
|
ignore_errors: true
|
|
|
|
|
|
- name: Set fact if mapping file present
|
|
|
set_fact:
|
|
|
- mapping_file_present: file_present.stdout
|
|
|
- when: mapping_file == "true"
|
|
|
+ mapping_file_present: "{{ file_present.stdout }}"
|
|
|
+ when: mapping_file | bool == true
|
|
|
ignore_errors: true
|
|
|
|
|
|
- name: Get the static hostname from mapping file
|
|
|
shell: awk -F',' '$3 == "{{ inventory_hostname }}" { print $2 }' ../../provision/files/new_mapping_file.csv
|
|
|
delegate_to: localhost
|
|
|
- when: ('localhost' in hostname_check.stdout) and (mapping_file_present != "" ) and ( mapping_file == "true" )
|
|
|
+ when: ('localhost' in hostname_check.stdout) and (mapping_file_present != "" ) and ( mapping_file | bool == true )
|
|
|
register: host_name
|
|
|
ignore_errors: true
|
|
|
|
|
@@ -89,23 +89,23 @@
|
|
|
hostname:
|
|
|
name: "{{ host_name.stdout }}"
|
|
|
register: result_host_name
|
|
|
- when: ('localhost' in hostname_check.stdout) and (mapping_file_present != "" ) and (mapping_file == "true" )
|
|
|
+ when: ('localhost' in hostname_check.stdout) and (mapping_file_present != "" ) and (mapping_file | bool == true )
|
|
|
ignore_errors: true
|
|
|
|
|
|
- name: Set the system hostname
|
|
|
hostname:
|
|
|
name: "compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1] }}"
|
|
|
register: result_name
|
|
|
- when: ('localhost' in hostname_check.stdout) and (mapping_file_present == "")
|
|
|
+ when: ('localhost' in hostname_check.stdout) and (mapping_file | bool == false)
|
|
|
ignore_errors: true
|
|
|
|
|
|
- - name: Add new hostname to /etc/hosts
|
|
|
+ - name: Add new hostname to /etc/hosts from mapping file
|
|
|
lineinfile:
|
|
|
dest: /etc/hosts
|
|
|
regexp: '^127\.0\.0\.1[ \t]+localhost'
|
|
|
line: "127.0.0.1 localhost {{ host_name.stdout }}"
|
|
|
state: present
|
|
|
- when: ('localhost' in hostname_check.stdout) and ( mapping_file_present != "" ) and ( mapping_file == "true" )
|
|
|
+ when: ('localhost' in hostname_check.stdout) and ( mapping_file_present != "" ) and ( mapping_file | bool == true )
|
|
|
ignore_errors: true
|
|
|
|
|
|
- name: Add new hostname to /etc/hosts
|
|
@@ -114,7 +114,7 @@
|
|
|
regexp: '^127\.0\.0\.1[ \t]+localhost'
|
|
|
line: "127.0.0.1 localhost 'compute{{ inventory_hostname.split('.')[-2] + '-' + inventory_hostname.split('.')[-1] }}'"
|
|
|
state: present
|
|
|
- when: ('localhost' in hostname_check.stdout) and (mapping_file_present == "" )
|
|
|
+ when: ('localhost' in hostname_check.stdout) and (mapping_file | bool == false )
|
|
|
ignore_errors: true
|
|
|
|
|
|
- name: Update inventory
|