123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- # Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ---
- - name: Find reachable hosts
- hosts: all
- gather_facts: false
- ignore_unreachable: true
- ignore_errors: true
- tasks:
- - name: Check for reachable nodes
- command: ping -c1 {{ inventory_hostname }}
- delegate_to: localhost
- register: ping_result
- ignore_errors: yes
- changed_when: false
- - name: Group reachable hosts
- group_by:
- key: "reachable"
- when: "'100% packet loss' not in ping_result.stdout"
- - name: Get provision password
- hosts: localhost
- connection: local
- gather_facts: false
- tasks:
- - name: Include vars file of inventory role
- include_vars: ../vars/main.yml
- - name: Set hostname on reachable nodes and gather facts
- hosts: reachable
- gather_facts: False
- remote_user: "{{ cobbler_username }}"
- vars:
- ansible_password: "{{ cobbler_password }}"
- ansible_become_pass: "{{ cobbler_password }}"
- tasks:
- - name: Setup
- setup:
- filter: ansible_*
- - name: Set the system hostname
- hostname:
- name: "compute{{ inventory_hostname.split('.')[-2] + '.' + inventory_hostname.split('.')[-1] }}"
- register: result_name
- - name: Add new hostname to /etc/hosts
- lineinfile:
- dest: /etc/hosts
- regexp: '^127\.0\.0\.1[ \t]+localhost'
- line: "127.0.0.1 localhost 'compute{{ inventory_hostname.split('.')[-1] }}'"
- state: present
- - name: Ensure networking connection
- command: nmcli networking off
- changed_when: false
- - name: Ensure networking connection
- command: nmcli networking on
- changed_when: false
- - name: Ensure networking connection
- command: nmcli networking on
- changed_when: false
- - name: Update inventory
- hosts: localhost
- connection: local
- gather_facts: false
- tasks:
- - name: Update inventory file
- block:
- - name: Fetch facts and add new hosts
- include_tasks: add_host.yml
- with_items: "{{ groups['reachable'] }}"
- when: "'reachable' in groups"
- - name: Show unreachable hosts
- debug:
- msg: "{{ host_unreachable_msg }} + {{ groups['ungrouped'] }}"
- when: "'ungrouped' in groups"
|