diff --git a/roles/nodepool-setup/defaults/main.yml b/roles/nodepool-setup/defaults/main.yml index b17329705..e4c435038 100644 --- a/roles/nodepool-setup/defaults/main.yml +++ b/roles/nodepool-setup/defaults/main.yml @@ -21,3 +21,50 @@ packages_list: - vim - wget - iptables-services +provider_node_label_primary: >- + {% if environment_type == 'ovb' -%} + tripleo-ovb-centos-7 + {%- else -%} + upstream-centos-7 + {%- endif -%} +env_hosts_block: >- + # + primary: + ansible_connection: ssh + ansible_host: "{{ hostvars[groups['subnodes'][0]].ansible_host }}" + ansible_private_key_file: "{{ hostvars[groups['subnodes'][0]].ansible_private_key_file }}" + ansible_port: 22 + ansible_user: zuul + nodepool: + az: nova + cloud: "{{ provider_cloud_name | default('rdo-cloud-tripleo') }}" + interface_ip: "{{ hostvars[groups['subnodes'][0]].ansible_host }}" + label: "{{ provider_node_label_primary }}" + private_ipv4: "{{ hostvars[groups['subnodes'][0]].subnode_private_ip }}" + provider: "{{ provider_name | default('rdo-cloud-tripleo') }}" + public_ipv4: "{{ hostvars[groups['subnodes'][0]].subnode_public_ip }}" + public_ipv6: "{{ hostvars[groups['subnodes'][0]].subnode_public_ipv6 | default('') }}" + region: "{{ provider_region_name | default('regionOne') }}" + {{ secondary_vars }} + vars: +secondary_vars: >- + {% if environment_type == 'multinode' -%} + secondary: + ansible_connection: ssh + ansible_host: "{{ hostvars[groups['subnodes'][1]].ansible_host }}" + ansible_private_key_file: "{{ hostvars[groups['subnodes'][1]].ansible_private_key_file }}" + ansible_port: 22 + ansible_user: zuul + nodepool: + az: nova + cloud: "{{ provider_cloud_name | default('rdo-cloud-tripleo') }}" + interface_ip: "{{ hostvars[groups['subnodes'][1]].ansible_host }}" + label: "{{ provider_node_label_primary }}" + private_ipv4: "{{ hostvars[groups['subnodes'][1]].subnode_private_ip }}" + provider: "{{ provider_name | default('rdo-cloud-tripleo') }}" + public_ipv4: "{{ hostvars[groups['subnodes'][1]].subnode_public_ip }}" + public_ipv6: "{{ hostvars[groups['subnodes'][1]].subnode_public_ipv6 | default('') }}" + region: "{{ provider_region_name | default('regionOne') }}" + {%- else -%} + # + {%- endif -%} diff --git a/roles/nodepool-setup/tasks/main.yml b/roles/nodepool-setup/tasks/main.yml index bacfb9822..00b8ed54e 100644 --- a/roles/nodepool-setup/tasks/main.yml +++ b/roles/nodepool-setup/tasks/main.yml @@ -1,4 +1,7 @@ --- +- include: modify-zuul-inventory.yml + +# Below this to be partly deleted - include: etc-nodepool.yml become: true diff --git a/roles/nodepool-setup/tasks/modify-zuul-inventory.yml b/roles/nodepool-setup/tasks/modify-zuul-inventory.yml new file mode 100644 index 000000000..97fa5a543 --- /dev/null +++ b/roles/nodepool-setup/tasks/modify-zuul-inventory.yml @@ -0,0 +1,63 @@ +- delegate_to: localhost + block: + + - name: Check if inventory file exists + stat: + path: "{{ lookup('env', 'WORKSPACE') }}/zuul_inventory.yaml" + register: zuul_inventory_file + + - name: Fail if file does not exist + fail: + msg: "zuul_inventory file does not exist in the workspace." + when: not zuul_inventory_file.stat.exists|bool + + - name: Remove CI hosts values + shell: "sed -i '/ primary:/,/ vars:/d' {{ lookup('env', 'WORKSPACE') }}/zuul_inventory.yaml" + + - name: Add env host values + blockinfile: + path: "{{ lookup('env', 'WORKSPACE') }}/zuul_inventory.yaml" + block: "{{ env_hosts_block }}" + insertafter: '^ hosts:$' + + - name: Modify zuul.executor hostname value + lineinfile: + path: "{{ lookup('env', 'WORKSPACE') }}/zuul_inventory.yaml" + regexp: '^ hostname:' + line: " hostname: localhost" + insertafter: '^ executor:$' + + - name: Modify zuul.executor dir values + replace: + path: "{{ lookup('env', 'WORKSPACE') }}/zuul_inventory.yaml" + regexp: "{{ item.start }}: .*/{{ item.end }}" + replace: "{{ item.start }}: {{ local_working_dir }}/zuul_tmp/{{ item.end }}" + with_items: + - { start: "inventory_file", end: "ansible/inventory.yaml" } + - { start: "log_root", end: "work/logs" } + - { start: "result_data_file", end: "work/results.json" } + - { start: "src_root", end: "work/src" } + - { start: "work_root", end: "work" } + + - name: Check if zuul_tmp exists + stat: + path: "{{ local_working_dir }}/zuul_tmp/" + register: zuul_tmp_dir + + - name: Create dir for zuul executor files if it does not exist + file : + path: "{{ local_working_dir }}/zuul_tmp/" + state: directory + when: not zuul_tmp_dir.stat.exists|bool + + - name: Create sub dirs in zuul_tmp_dir + file: + path: "{{ local_working_dir }}/zuul_tmp/{{ item }}" + state: directory + with_items: + - "ansible" + - "work" + - "work/logs" + - "work/src" + when: not zuul_tmp_dir.stat.exists|bool +