<commit_before>- name: Stop and disable openstack services and libvirtd
  hosts: compute
  become: yes
  any_errors_fatal: true
  tasks:
      - service:
            name: "{{ item }}"
            state: stopped
            enabled: no
        with_items:
            - neutron-openvswitch-agent
            - openstack-ceilometer-compute
            - openstack-nova-compute
            - libvirtd

- name: Generate authkey for remote pacemaker
  hosts: localhost
  tasks:
      - shell: "dd if=/dev/urandom of='{{ inventory_dir }}/authkey' bs=4096 count=1"

- name: Deploy auth key
  hosts: controller:compute
  become: yes
  gather_facts: yes
  any_errors_fatal: true
  tasks:
      - name: Make sure pacemaker config dir exists
        file:
            path: /etc/pacemaker
            state: directory
            mode: 0755

      - name: Copy generated autkey to overcloud nodes
        copy:
            src: "{{ inventory_dir }}/authkey"
            dest: /etc/pacemaker/
            mode: 0644

- name: Enable and start remote_pacemaker on computes
  hosts: compute
  become: yes
  any_errors_fatal: true
  tasks:
      - name: Open pacemaker_remote port
        shell: "iptables -I INPUT -p tcp --dport 3121 -j ACCEPT"

      - name: Make created iptables rules persistant
        shell: "/sbin/service iptables save"

      - name: Start pacemaker remote service at compute nodes
        service:
            name: pacemaker_remote
            enabled: yes
            state: started

- name: Get the overcloud rc file
  hosts: undercloud
  gather_facts: no
  any_errors_fatal: true
  tasks:
      - fetch:
            src: "~/overcloudrc"
            dest: "{{ inventory_dir }}/keystonerc"
            flat: yes

- name: Set overcloud credentials
  hosts: controller[0]
  any_errors_fatal: true
  roles:
      - {role: installer/ospd/overcloud/credentials, overcloudrc: "{{ inventory_dir }}/keystonerc" }

- name: Run setup as root, to get all Ansible facts
  hosts: controller
  gather_facts: yes
  become: yes
  become_method: sudo
  any_errors_fatal: true
  tasks:
      - setup:

- name: Setup pacemaker for instance HA
  hosts: controller[0]
  gather_facts: yes
  become: yes
  environment:
      OS_USERNAME: "{{ oc_username.stdout | default('admin') }}"
      OS_PASSWORD: "{{ oc_<PASSWORD> }}"
      OS_AUTH_URL: "{{ oc_auth.stdout }}"
      OS_TENANT_NAME: "{{ oc_tenant.stdout | default('admin') }}"
  any_errors_fatal: true
  tasks:
      - name: Create NovaEvacuate resource
        shell: "pcs resource create nova-evacuate ocf:openstack:NovaEvacuate auth_url=$OS_AUTH_URL username=$OS_USERNAME password=$<PASSWORD> tenant_name=$OS_TENANT_NAME no_shared_storage=0"

      - name: Create pacemaker constraints to start VIP resources before nova-evacuate
        shell: |
            for i in $(pcs status | grep IP | awk '{ print $1 }')
              do pcs constraint order start $i then nova-evacuate
            done

      - name: Create pacemaker constraints to start openstack services before nova-evacuate
        shell: "pcs constraint order start {{ item }} then nova-evacuate require-all=false"
        with_items:
            - openstack-glance-api-clone
            - neutron-metadata-agent-clone
            - openstack-nova-conductor-clone
        when: "{{ installer.product.version|openstack_release }} < 10"

      - name: Disable keystone resource
        shell: "pcs resource disable openstack-keystone --wait=900"
        when: "{{ installer.product.version|openstack_release }} < 9"

      # Keystone resource was replaced by openstack-core resource in RHOS9
      - name: Disable openstack-core resource
        shell: "pcs resource disable openstack-core --wait=900"
        when: "{{ installer.product.version|openstack_release }} == 9"

      - name: Set controller pacemaker property on controllers
        shell: "pcs property set --node {{ hostvars[item]['ansible_hostname'] }} osprole=controller"
        with_items: "{{ groups['controller'] }}"

      - name: Get stonith devices
        shell: "pcs stonith | awk '{print $1}' | tr '\n' ' '"
        register: stonithdevs

      - name: Setup stonith devices
        shell: |
            for i in $(sudo cibadmin -Q --xpath //primitive --node-path | awk -F "id='" '{print $2}' | awk -F "'" '{print $1}' | uniq); do
              found=0
              if [ -n "{{ stonithdevs.stdout }}" ]; then
                for x in {{ stonithdevs.stdout }}; do
                  if [ "$x" == "$i" ]; then
                    found=1
                  fi
                done
              fi
              if [ $found = 0 ]; then
                sudo pcs constraint location $i rule resource-discovery=exclusive score=0 osprole eq controller
              fi
            done

      - name: Create compute pacemaker resources and constraints
        shell: |
            pcs resource create neutron-openvswitch-agent-compute systemd:neutron-openvswitch-agent --clone interleave=true --disabled --force
            pcs constraint location neutron-openvswitch-agent-compute-clone rule resource-discovery=exclusive score=0 osprole eq compute
            pcs resource create libvirtd-compute systemd:libvirtd --clone interleave=true --disabled --force
            pcs constraint location libvirtd-compute-clone rule resource-discovery=exclusive score=0 osprole eq compute
            pcs constraint order start neutron-openvswitch-agent-compute-clone then libvirtd-compute-clone
            pcs constraint colocation add libvirtd-compute-clone with neutron-openvswitch-agent-compute-clone
            pcs resource create ceilometer-compute systemd:openstack-ceilometer-compute --clone interleave=true --disabled --force
            pcs constraint location ceilometer-compute-clone rule resource-discovery=exclusive score=0 osprole eq compute
            pcs constraint order start libvirtd-compute-clone then ceilometer-compute-clone
            pcs constraint colocation add ceilometer-compute-clone with libvirtd-compute-clone

            pcs resource create nova-compute-checkevacuate ocf:openstack:nova-compute-wait auth_url=$OS_AUTH_URL username=$OS_USERNAME password=$<PASSWORD> tenant_name=$OS_TENANT_NAME domain=localdomain op start timeout=300 --clone interleave=true --disabled --force
            pcs constraint location nova-compute-checkevacuate-clone rule resource-discovery=exclusive score=0 osprole eq compute

            pcs resource create nova-compute systemd:openstack-nova-compute --clone interleave=true --disabled --force
            pcs constraint location nova-compute-clone rule resource-discovery=exclusive score=0 osprole eq compute
            pcs constraint order start nova-compute-checkevacuate-clone then nova-compute-clone require-all=true

            pcs constraint order start nova-compute-clone then nova-evacuate require-all=false
            pcs constraint order start libvirtd-compute-clone then nova-compute-clone
            pcs constraint colocation add nova-compute-clone with libvirtd-compute-clone

      - name: Create nova-compute order constraint on galera-master
        shell: "pcs constraint order promote galera-master then nova-compute-clone require-all=false"
        when: "{{ installer.product.version|openstack_release }} > 9"

      - name: Create pacemaker constraint for neutron-server, nova-conductor and ceilometer-notification
        shell: |
            pcs constraint order start neutron-server-clone then neutron-openvswitch-agent-compute-clone require-all=false
            pcs constraint order start openstack-ceilometer-notification-clone then ceilometer-compute-clone require-all=false
            pcs constraint order start openstack-nova-conductor-clone then nova-compute-checkevacuate-clone require-all=false
        when: "{{ installer.product.version|openstack_release }} < 10"

      # TODO (mkrcmari) Create a play for baremetal computes fencing setup
      - name: Set up virt-fencing for compute nodes
        shell: |
            COMPUTENAME={{ hostvars[item]['ansible_hostname'] }}
            VM_UUID={{ hostvars[item]['ansible_product_uuid'] }}
            pcs stonith delete my-stonith-xvm-$COMPUTENAME || /bin/true
            pcs stonith create my-stonith-xvm-$COMPUTENAME fence_xvm port=$VM_UUID pcmk_host_list=$COMPUTENAME use_uuid=1 op monitor interval=30s
        with_items: "{{ groups['compute'] }}"
        when: "'virthost' in groups"

      - name: Create fence-nova pacemaker resource
        shell: "pcs stonith create fence-nova fence_compute auth-url=$OS_AUTH_URL login=$OS_USERNAME passwd=$<PASSWORD> tenant-name=$OS_TENANT_NAME domain=localdomain record-only=1 no-shared-storage=False action=off --force"

      - name: Set cluster recheck interval to 1 minute
        shell: "pcs property set cluster-recheck-interval=1min"

      - name: Create pacemaker remote resource on compute nodes
        shell: "pcs resource create {{ hostvars[item]['ansible_hostname'] }} ocf:pacemaker:remote reconnect_interval=240 op monitor interval=20"<commit_msg>instance_ha: Create pcmk constraint on fence-nova<commit_after>- name: Stop and disable openstack services and libvirtd
  hosts: compute
  become: yes
  any_errors_fatal: true
  tasks:
      - service:
            name: "{{ item }}"
            state: stopped
            enabled: no
        with_items:
            - neutron-openvswitch-agent
            - openstack-ceilometer-compute
            - openstack-nova-compute
            - libvirtd

- name: Generate authkey for remote pacemaker
  hosts: localhost
  tasks:
      - shell: "dd if=/dev/urandom of='{{ inventory_dir }}/authkey' bs=4096 count=1"

- name: Deploy auth key
  hosts: controller:compute
  become: yes
  gather_facts: yes
  any_errors_fatal: true
  tasks:
      - name: Make sure pacemaker config dir exists
        file:
            path: /etc/pacemaker
            state: directory
            mode: 0755

      - name: Copy generated autkey to overcloud nodes
        copy:
            src: "{{ inventory_dir }}/authkey"
            dest: /etc/pacemaker/
            mode: 0644

- name: Enable and start remote_pacemaker on computes
  hosts: compute
  become: yes
  any_errors_fatal: true
  tasks:
      - name: Open pacemaker_remote port
        shell: "iptables -I INPUT -p tcp --dport 3121 -j ACCEPT"

      - name: Make created iptables rules persistant
        shell: "/sbin/service iptables save"

      - name: Start pacemaker remote service at compute nodes
        service:
            name: pacemaker_remote
            enabled: yes
            state: started

- name: Get the overcloud rc file
  hosts: undercloud
  gather_facts: no
  any_errors_fatal: true
  tasks:
      - fetch:
            src: "~/overcloudrc"
            dest: "{{ inventory_dir }}/keystonerc"
            flat: yes

- name: Set overcloud credentials
  hosts: controller[0]
  any_errors_fatal: true
  roles:
      - {role: installer/ospd/overcloud/credentials, overcloudrc: "{{ inventory_dir }}/keystonerc" }

- name: Run setup as root, to get all Ansible facts
  hosts: controller
  gather_facts: yes
  become: yes
  become_method: sudo
  any_errors_fatal: true
  tasks:
      - setup:

- name: Setup pacemaker for instance HA
  hosts: controller[0]
  gather_facts: yes
  become: yes
  environment:
      OS_USERNAME: "{{ oc_username.stdout | default('admin') }}"
      OS_PASSWORD: "{{ oc_<PASSWORD> }}"
      OS_AUTH_URL: "{{ oc_auth.stdout }}"
      OS_TENANT_NAME: "{{ oc_tenant.stdout | default('admin') }}"
  any_errors_fatal: true
  tasks:
      - name: Create NovaEvacuate resource
        shell: "pcs resource create nova-evacuate ocf:openstack:NovaEvacuate auth_url=$OS_AUTH_URL username=$OS_USERNAME password=$OS_PASSWORD tenant_name=$OS_TENANT_NAME no_shared_storage=0"

      - name: Create pacemaker constraints to start VIP resources before nova-evacuate
        shell: |
            for i in $(pcs status | grep IP | awk '{ print $1 }')
              do pcs constraint order start $i then nova-evacuate
            done

      - name: Create pacemaker constraints to start openstack services before nova-evacuate
        shell: "pcs constraint order start {{ item }} then nova-evacuate require-all=false"
        with_items:
            - openstack-glance-api-clone
            - neutron-metadata-agent-clone
            - openstack-nova-conductor-clone
        when: "{{ installer.product.version|openstack_release }} < 10"

      - name: Disable keystone resource
        shell: "pcs resource disable openstack-keystone --wait=900"
        when: "{{ installer.product.version|openstack_release }} < 9"

      # Keystone resource was replaced by openstack-core resource in RHOS9
      - name: Disable openstack-core resource
        shell: "pcs resource disable openstack-core --wait=900"
        when: "{{ installer.product.version|openstack_release }} == 9"

      - name: Set controller pacemaker property on controllers
        shell: "pcs property set --node {{ hostvars[item]['ansible_hostname'] }} osprole=controller"
        with_items: "{{ groups['controller'] }}"

      - name: Get stonith devices
        shell: "pcs stonith | awk '{print $1}' | tr '\n' ' '"
        register: stonithdevs

      - name: Setup stonith devices
        shell: |
            for i in $(sudo cibadmin -Q --xpath //primitive --node-path | awk -F "id='" '{print $2}' | awk -F "'" '{print $1}' | uniq); do
              found=0
              if [ -n "{{ stonithdevs.stdout }}" ]; then
                for x in {{ stonithdevs.stdout }}; do
                  if [ "$x" == "$i" ]; then
                    found=1
                  fi
                done
              fi
              if [ $found = 0 ]; then
                sudo pcs constraint location $i rule resource-discovery=exclusive score=0 osprole eq controller
              fi
            done

      - name: Create compute pacemaker resources and constraints
        shell: |
            pcs resource create neutron-openvswitch-agent-compute systemd:neutron-openvswitch-agent --clone interleave=true --disabled --force
            pcs constraint location neutron-openvswitch-agent-compute-clone rule resource-discovery=exclusive score=0 osprole eq compute
            pcs resource create libvirtd-compute systemd:libvirtd --clone interleave=true --disabled --force
            pcs constraint location libvirtd-compute-clone rule resource-discovery=exclusive score=0 osprole eq compute
            pcs constraint order start neutron-openvswitch-agent-compute-clone then libvirtd-compute-clone
            pcs constraint colocation add libvirtd-compute-clone with neutron-openvswitch-agent-compute-clone
            pcs resource create ceilometer-compute systemd:openstack-ceilometer-compute --clone interleave=true --disabled --force
            pcs constraint location ceilometer-compute-clone rule resource-discovery=exclusive score=0 osprole eq compute
            pcs constraint order start libvirtd-compute-clone then ceilometer-compute-clone
            pcs constraint colocation add ceilometer-compute-clone with libvirtd-compute-clone

            pcs resource create nova-compute-checkevacuate ocf:openstack:nova-compute-wait auth_url=$OS_AUTH_URL username=$OS_USERNAME password=$<PASSWORD> tenant_name=$OS_TENANT_NAME domain=localdomain op start timeout=300 --clone interleave=true --disabled --force
            pcs constraint location nova-compute-checkevacuate-clone rule resource-discovery=exclusive score=0 osprole eq compute

            pcs resource create nova-compute systemd:openstack-nova-compute op start timeout=60s --clone interleave=true --disabled --force
            pcs constraint location nova-compute-clone rule resource-discovery=exclusive score=0 osprole eq compute
            pcs constraint order start nova-compute-checkevacuate-clone then nova-compute-clone require-all=true

            pcs constraint order start nova-compute-clone then nova-evacuate require-all=false
            pcs constraint order start libvirtd-compute-clone then nova-compute-clone
            pcs constraint colocation add nova-compute-clone with libvirtd-compute-clone

      - name: Create pacemaker constraint for neutron-server, nova-conductor and ceilometer-notification
        shell: |
            pcs constraint order start neutron-server-clone then neutron-openvswitch-agent-compute-clone require-all=false
            pcs constraint order start openstack-ceilometer-notification-clone then ceilometer-compute-clone require-all=false
            pcs constraint order start openstack-nova-conductor-clone then nova-compute-checkevacuate-clone require-all=false
        when: "{{ installer.product.version|openstack_release }} < 10"

      # TODO (mkrcmari) Create a play for baremetal computes fencing setup
      - name: Set up virt-fencing for compute nodes
        shell: |
            COMPUTENAME={{ hostvars[item]['ansible_hostname'] }}
            VM_UUID={{ hostvars[item]['ansible_product_uuid'] }}
            pcs stonith delete my-stonith-xvm-$COMPUTENAME || /bin/true
            pcs stonith create my-stonith-xvm-$COMPUTENAME fence_xvm port=$VM_UUID pcmk_host_list=$COMPUTENAME use_uuid=1 op monitor interval=30s
        with_items: "{{ groups['compute'] }}"
        when: "'virthost' in groups"

      - name: Create fence-nova pacemaker resource
        shell: "pcs stonith create fence-nova fence_compute auth-url=$OS_AUTH_URL login=$OS_USERNAME passwd=$<PASSWORD> tenant-name=$OS_TENANT_NAME domain=localdomain record-only=1 no-shared-storage=False action=off --force"

      - name: Create pacemaker constraint for fence-nova to start after galera
        shell: "pcs constraint order promote galera-master then fence-nova require-all=false"

      - name: Create nova-compute order constraint on fence-nova
        shell: "pcs constraint order start fence-nova then nova-compute-clone"

      - name: Set cluster recheck interval to 1 minute
        shell: "pcs property set cluster-recheck-interval=1min"

      - name: Create pacemaker remote resource on compute nodes
        shell: "pcs resource create {{ hostvars[item]['ansible_hostname'] }} ocf:pacemaker:remote reconnect_interval=240 op monitor interval=20"
{'fraction_non_alphanumeric': 0.08639806784498848, 'fraction_numerical': 0.006751564386870129, 'mean_word_length': 2.68955042527339, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3430535', 'n_tokens_mistral': 5306, 'n_tokens_neox': 5054, 'n_words': 1500}