Skip to content
Snippets Groups Projects
playbook.yml 1.13 KiB
Newer Older
nikola.antonije's avatar
nikola.antonije committed
---
- name: Configuration et démarrage des interfaces réseau
  hosts: all
  become: true
  tasks:
  - name: Load the variables
    include_vars: variables.yml
  - name: Rename hosts
    hostname:
      name: "{{ inventory_hostname }}"
  # For H1 and H2, we config network interfaces
  - name: Setup network for Hosts
    become: true
    when: "'H1' in inventory_hostname or 'H2' in inventory_hostname"
    template:
      src: ./templates/host.j2
      dest: /etc/network/interfaces.d/eth.conf
      mode: 0640
    notify: Restart network
  - name: Setup network for Routers
    when: "'routers' in group_names"
    become: true
    template:
      src: ./templates/router.j2
      dest: /etc/network/interfaces.d/eth.conf
      mode: 0640
    notify: Restart network
  handlers:
  - name: Restart network
    service:
      name: networking
      state: restarted
      enabled: true
      
# Test en effectuant un ping de H1 à H2
- name: Display ping value
  hosts: H1
  become: true
  tasks:
  - name: Ping form H1 to H2
    shell: "ping 3.0.0.3 -c 1"
    register: result
  - name: Print result
    debug:
      msg: "{{ result.stdout_lines }}"
...