- hosts: controller
  tasks:
    - name: create local.sh
      become: yes
      blockinfile:
        path: /opt/stack/devstack/local.sh
        create: True
        mode: 0777
        block: |
          # creating an nfv flavor used in tempest
          # primary flavor
          name=nfv-64-1-1
          openstack flavor create --id 420 --ram 64 --disk 1 --vcpus 1 $name
          openstack flavor set --property hw:mem_page_size=large 420

          # secondary flavor
          name=nfv-128-1-2
          openstack flavor create --id 840 --ram 128 --disk 1 --vcpus 2 $name
          openstack flavor set --property hw:mem_page_size=2MB \
          --property hw:cpu_policy=dedicated \
          --property hw:emulator_threads_policy=share \
          --property hw:cpu_realtime=yes --property hw:cpu_realtime_mask=^0 \
          840

- hosts: all
  tasks:
    - name: install dpdk deps
      become: yes
      package:
        name: "{{item}}"
        state: present
      with_items:
        - "numactl-devel"
        - "gcc"
        - "make"
        - "python3-devel"
        - "kernel-headers"
        - "kernel-devel"
      when: ansible_os_family == 'RedHat'


- hosts: all
  tasks:
    - name: install dpdk deps
      become: yes
      package:
        name: "{{item}}"
        state: present
      with_items:
        - "libnuma-dev"
        - "gcc"
        - "make"
        - "python3-dev"
        - "linux-headers-generic"
        - "build-essential"
      when: ansible_os_family == 'Debian'


- hosts: controller
  tasks:
    - name: allocate hugepages
      shell: echo 512 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
      become: yes

- hosts: subnode
  tasks:
    - name: allocate hugepages
      shell: echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
      become: yes
