diff --git a/.gitignore b/.gitignore index d7f5bd7d..32b9cae3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ *~ playbooks/.vagrant -playbooks/ansible/vagrant_ansible_inventory +playbooks/ansible/site_inventory playbooks/ansible/ssh-config-setup -playbooks/vagrant_ansible_inventory +playbooks/site_inventory playbooks/ssh-config-host playbooks/Vagrantfile playbooks/ansible/config.yml diff --git a/devel/Makefile b/devel/Makefile index 37adcd31..053e803e 100644 --- a/devel/Makefile +++ b/devel/Makefile @@ -5,3 +5,9 @@ fix_ssh: centos8_build_setup: @ansible-playbook -i ${INVENTORY} centos8_build_setup.yml + +centos9_build_setup: + @ansible-playbook -i ${INVENTORY} centos9_build_setup.yml + +single_node_samba_cluster: + @ansible-playbook -i ${INVENTORY} single_node_samba_cluster.yml diff --git a/devel/centos8_build_setup.yml b/devel/centos8_build_setup.yml index 81b19c9d..e0b609d1 100644 --- a/devel/centos8_build_setup.yml +++ b/devel/centos8_build_setup.yml @@ -1,5 +1,5 @@ --- -- hosts: cluster +- hosts: storage0 become: yes tasks: diff --git a/devel/centos9_build_setup.yml b/devel/centos9_build_setup.yml new file mode 100644 index 00000000..b12a6286 --- /dev/null +++ b/devel/centos9_build_setup.yml @@ -0,0 +1,98 @@ +--- +- hosts: storage0 + become: yes + tasks: + + - name: Install storage SIG packages + dnf: + name: + - centos-release-gluster10 + + # Grabbed list of packages from + # https://github.com/samba-in-kubernetes/samba-build/blob/main/packaging/samba-4.19.spec.j2 + - name: Install required rpms + dnf: + name: + - git + - gdb + - make + - gcc + - glibc-gconv-extra + - avahi-devel + - bison + - cups-devel + - dbus-devel + - docbook-style-xsl + - e2fsprogs-devel + - flex + - gawk + - gnupg2 + - gnutls-devel + - gpgme-devel + - jansson-devel + - krb5-devel + - libacl-devel + - libaio-devel + - libarchive-devel + - libattr-devel + - libcap-devel + - libicu-devel + - libcmocka-devel + - libtirpc-devel + - libuuid-devel + - libxslt + - lmdb + - mingw32-gcc + - mingw64-gcc + - ncurses-devel + - openldap-devel + - pam-devel + - perl-interpreter + - perl-generators + - perl(Archive::Tar) + - perl(Test::More) + - popt-devel + - python3-cryptography + - python3-devel + - python3-dns + - python3-requests + - python3-setuptools + - quota-devel + - readline-devel + - rpcgen + - rpcsvc-proto-devel + - sed + - systemd-rpm-macros + - libtasn1-devel + - libtasn1-tools + - xfsprogs-devel + - xz + - zlib-devel + - pkgconfig(libsystemd) + - mold + - libgfapi-devel + - libglusterfs-devel + - libcephfs-devel + - liburing-devel + - pcp-libs-devel + - librados-devel + - python3-iso8601 + - python3-pyasn1 + - bind + - krb5-server + - perl(ExtUtils::MakeMaker) + - perl(FindBin) + - perl(Parse::Yapp) + - lmdb-devel + - bind + - krb5-server + - python3-dateutil + - python3-iso8601 + - python3-pyasn1 + - ldb-tools + - python3-gpg + - python3-markdown + - python3-cryptography + - python3-setproctitle + - tdb-tools + state: latest diff --git a/devel/inventory b/devel/inventory index 7213b6d2..7219aaeb 120000 --- a/devel/inventory +++ b/devel/inventory @@ -1 +1 @@ -../vagrant/vagrant_ansible_inventory \ No newline at end of file +../playbooks/site_inventory \ No newline at end of file diff --git a/devel/single_node_samba_cluster.yml b/devel/single_node_samba_cluster.yml new file mode 100644 index 00000000..1e848e01 --- /dev/null +++ b/devel/single_node_samba_cluster.yml @@ -0,0 +1,27 @@ +--- +- hosts: cluster + become: yes + tasks: + + - name: Stop ctdb service + ansible.builtin.service: + name: ctdb + state: stopped + enabled: no + + - name: Disable clustering in smb.conf + ansible.builtin.lineinfile: + path: /etc/samba/smb.conf + search_string: "clustering" + line: clustering = no + + - name: Start smb service on storage0 + ansible.builtin.service: + name: smb + state: started + enabled: yes + when: ansible_hostname == "storage0" + + - name: Add test1 user to samba standalone tdb + shell: (echo x; echo x)|smbpasswd -a test1 + when: ansible_hostname == "storage0" diff --git a/playbooks/Makefile b/playbooks/Makefile index d7bcb85a..e94fbb93 100644 --- a/playbooks/Makefile +++ b/playbooks/Makefile @@ -1,6 +1,5 @@ -INVENTORY := ./vagrant_ansible_inventory +INVENTORY := ./site_inventory VSSH := ssh -F ssh-config-host -VAGRANT := vagrant ifdef EXTRA_VARS ANSIBLE_EXTRA_VARS := -e '${EXTRA_VARS}' @@ -25,34 +24,28 @@ setup.test.only: @ansible-playbook --inventory=$(INVENTORY) ${ANSIBLE_EXTRA_VARS} setup.test.yml setup.cluster.only: - @$(VSSH) admin "${SSH_EXTRA_VARS} make -C /home/vagrant/ansible setup.cluster" + @$(VSSH) admin "${SSH_EXTRA_VARS} make -C ansible setup.cluster" setup.cluster: setup.prep setup.test.only setup.cluster.only setup.clients: - @$(VSSH) admin "${SSH_EXTRA_VARS} make -C /home/vagrant/ansible setup.clients" + @$(VSSH) admin "${SSH_EXTRA_VARS} make -C ansible setup.clients" generate.report: - @$(VSSH) admin "${SSH_EXTRA_VARS} make -C /home/vagrant/ansible generate.report" + @$(VSSH) admin "${SSH_EXTRA_VARS} make -C ansible generate.report" nodes.statedump: @ansible-playbook --inventory $(INVENTORY) ${ANSIBLE_EXTRA_VARS} nodes.statedump.yml client.test: - @$(VSSH) admin "${SSH_EXTRA_VARS} make -C /home/vagrant/ansible client.test" + @$(VSSH) admin "${SSH_EXTRA_VARS} make -C ansible client.test" setup.site: setup.cluster setup.clients generate.report client.test client1.test: @$(VSSH) clients "sudo make -C /root/sit-test-cases test" -clean_vagrant: - -$(VAGRANT) destroy -f - -rm -rf .vagrant +clean: + @ansible-playbook --inventory localhost, ${ANSIBLE_EXTRA_VARS} cleanup.yml -clean_generated_files: - -rm -f Vagrantfile ansible/config.yml ansible/vagrant_ansible_inventory ansible/ssh-config-setup vagrant_ansible_inventory ssh-config-host - -clean: clean_vagrant clean_generated_files - -.PHONY: local hosts.update.only setup.prep.only setup.prep setup.test.only setup.cluster.only setup.cluster setup.clients client.test setup.site client1.test clean_vagrant clean_generated_files clean +.PHONY: local hosts.update.only setup.prep.only setup.prep setup.test.only setup.cluster.only setup.cluster setup.clients client.test setup.site client1.test clean diff --git a/playbooks/ansible/Makefile b/playbooks/ansible/Makefile index 09c78f58..42722088 100644 --- a/playbooks/ansible/Makefile +++ b/playbooks/ansible/Makefile @@ -1,4 +1,4 @@ -INVENTORY := ./vagrant_ansible_inventory +INVENTORY := ./site_inventory ifdef EXTRA_VARS ANSIBLE_EXTRA_VARS := -e '${EXTRA_VARS}' @@ -17,7 +17,7 @@ generate.report: @ansible-playbook -i $(INVENTORY) ${ANSIBLE_EXTRA_VARS} ./generate-report.yml client.test: - @ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook -i $(INVENTORY) ${ANSIBLE_EXTRA_VARS} ./client-test.yml + @ansible-playbook -i $(INVENTORY) ${ANSIBLE_EXTRA_VARS} ./client-test.yml setup.site: setup.cluster setup.clients client.test diff --git a/playbooks/ansible/vagrant_insecure_private_ssh_key b/playbooks/ansible/insecure_private_ssh_key similarity index 100% rename from playbooks/ansible/vagrant_insecure_private_ssh_key rename to playbooks/ansible/insecure_private_ssh_key diff --git a/playbooks/ansible/roles/client.test/tasks/main.yml b/playbooks/ansible/roles/client.test/tasks/main.yml deleted file mode 100644 index 7517604a..00000000 --- a/playbooks/ansible/roles/client.test/tasks/main.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- name: Run tests - block: - - command: - chdir: /root/sit-test-cases - cmd: make test - register: test_output - - debug: var=test_output.stdout_lines - when: test_sanity_only is undefined - -- name: Run sanity tests - block: - - command: - chdir: /root/sit-test-cases - cmd: make sanity_test - register: test_output - - debug: var=test_output.stdout_lines - when: test_sanity_only is defined diff --git a/playbooks/ansible/roles/common.prep/tasks/main.yml b/playbooks/ansible/roles/common.prep/tasks/main.yml index 5973ed53..eee4de06 100644 --- a/playbooks/ansible/roles/common.prep/tasks/main.yml +++ b/playbooks/ansible/roles/common.prep/tasks/main.yml @@ -13,18 +13,18 @@ - name: create ansible directory (for ssh key) file: - path: /home/vagrant/ansible + path: ansible state: directory - name: copy ssh key copy: - src: /home/vagrant/ansible/vagrant_insecure_private_ssh_key - dest: /home/vagrant/ansible/vagrant_insecure_private_ssh_key + src: insecure_private_ssh_key + dest: ansible/insecure_private_ssh_key - name: copy ssh config copy: src: ssh-config-setup - dest: /home/vagrant/.ssh/config + dest: .ssh/config - name: Create /etc/hosts template: diff --git a/playbooks/ansible/roles/ctdb.setup/tasks/main.yml b/playbooks/ansible/roles/ctdb.setup/tasks/main.yml index bcf1b0f0..3031725e 100644 --- a/playbooks/ansible/roles/ctdb.setup/tasks/main.yml +++ b/playbooks/ansible/roles/ctdb.setup/tasks/main.yml @@ -82,3 +82,16 @@ - name: Restart ctdb service: name=ctdb state=restarted enabled=yes + +- name: Ensure cluster is in HEALTHY state + run_once: yes + command: ctdb nodestatus all + register: nodestatus + until: nodestatus.rc == 0 + retries: 20 + delay: 3 + +- name: Create test users with smbpasswd + shell: (echo {{ item.password }}; echo {{ item.password }})|smbpasswd -a {{ item.username }} + with_items: "{{ samba_users }}" + run_once: yes diff --git a/playbooks/ansible/roles/samba.setup/tasks/main.yml b/playbooks/ansible/roles/samba.setup/tasks/main.yml index ff8abbb7..5a7fc6dd 100644 --- a/playbooks/ansible/roles/samba.setup/tasks/main.yml +++ b/playbooks/ansible/roles/samba.setup/tasks/main.yml @@ -49,19 +49,9 @@ vars: name: '{{ item.share_name }}-{{ config.be.name }}-{{ config.be.variant }}' -- name: Restart samba - service: - name: smb - state: restarted - - name: Create test users user: name: "{{ item.username }}" uid: "{{ item.uid }}" state: present with_items: "{{ samba_users }}" - -- name: Create test users with smbpasswd - shell: (echo {{ item.password }}; echo {{ item.password }})|smbpasswd -a {{ item.username }} - with_items: "{{ samba_users }}" - run_once: yes diff --git a/playbooks/ansible/roles/sit.cephfs/tasks/server/main.yml b/playbooks/ansible/roles/sit.cephfs/tasks/server/main.yml index 8ecc382b..affe545b 100644 --- a/playbooks/ansible/roles/sit.cephfs/tasks/server/main.yml +++ b/playbooks/ansible/roles/sit.cephfs/tasks/server/main.yml @@ -17,7 +17,7 @@ fetch: flat: true src: /root/.ssh/id_rsa.pub - dest: "/home/vagrant/ansible/ceph-node-0-ssh-key.pub" + dest: ceph-node-0-ssh-key.pub - name: Populating non-bootstrap nodes authorized keys authorized_key: @@ -25,7 +25,7 @@ state: present key: "{{ lookup('file', pubkey) }}" vars: - pubkey: "/home/vagrant/ansible/ceph-node-0-ssh-key.pub" + pubkey: ceph-node-0-ssh-key.pub # Pull ceph container image for all nodes - name: Pull containers diff --git a/playbooks/ansible/roles/test.sit-test-cases/tasks/main.yml b/playbooks/ansible/roles/test.sit-test-cases/tasks/main.yml index 7517604a..1abd8997 100644 --- a/playbooks/ansible/roles/test.sit-test-cases/tasks/main.yml +++ b/playbooks/ansible/roles/test.sit-test-cases/tasks/main.yml @@ -1,18 +1,12 @@ --- - name: Run tests - block: - - command: - chdir: /root/sit-test-cases - cmd: make test - register: test_output - - debug: var=test_output.stdout_lines + shell: + chdir: /root/sit-test-cases + cmd: make test &> /var/log/test.out when: test_sanity_only is undefined - name: Run sanity tests - block: - - command: - chdir: /root/sit-test-cases - cmd: make sanity_test - register: test_output - - debug: var=test_output.stdout_lines + shell: + chdir: /root/sit-test-cases + cmd: make sanity_test &> /var/log/test.out when: test_sanity_only is defined diff --git a/playbooks/ansible/roles/tests/tasks/log.yml b/playbooks/ansible/roles/tests/tasks/log.yml index d59efced..d9b90a1c 100644 --- a/playbooks/ansible/roles/tests/tasks/log.yml +++ b/playbooks/ansible/roles/tests/tasks/log.yml @@ -1,6 +1,5 @@ --- - name: Add a log entry to site-tests.log - delegate_to: localhost block: - name: Get current time command: date "+%Y-%m-%d %H-%M-%S.%3N" @@ -8,7 +7,7 @@ - name: Write the log entry to site-tests.log lineinfile: - dest: "{{ config.statedir }}/site-tests.log" + dest: /var/log/site-tests.log line: "{{ now.stdout }} {{ line }}" insertafter: EOF create: true diff --git a/playbooks/ansible/roles/tests/tasks/main.yml b/playbooks/ansible/roles/tests/tasks/main.yml index 1969364c..2dc95ee3 100644 --- a/playbooks/ansible/roles/tests/tasks/main.yml +++ b/playbooks/ansible/roles/tests/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: Initialize test result + set_fact: + tests_failed: false + - name: Run tests include_tasks: run-test.yml vars: @@ -6,3 +10,8 @@ loop: "{{ config.tests }}" loop_control: loop_var: test_name + +- name: Check that tests succeeded + when: tests_failed + fail: + msg: "Some tests have failed" diff --git a/playbooks/ansible/roles/tests/tasks/run-test.yml b/playbooks/ansible/roles/tests/tasks/run-test.yml index e95797fc..805b5d08 100644 --- a/playbooks/ansible/roles/tests/tasks/run-test.yml +++ b/playbooks/ansible/roles/tests/tasks/run-test.yml @@ -41,6 +41,10 @@ name: "{{ role }}" tasks_from: recover/main.yml + - name: Mark the test as failed + set_fact: + tests_failed: true + always: - name: Log test finalization time include_tasks: log.yml diff --git a/playbooks/ansible/setup-cluster.yml b/playbooks/ansible/setup-cluster.yml index 84ee4dc1..84cb64a1 100644 --- a/playbooks/ansible/setup-cluster.yml +++ b/playbooks/ansible/setup-cluster.yml @@ -9,5 +9,5 @@ - common.prep - node.prep - "sit.{{ config.be.name }}" - - ctdb.setup - samba.setup + - ctdb.setup diff --git a/playbooks/cleanup.yml b/playbooks/cleanup.yml new file mode 100644 index 00000000..e768ea1e --- /dev/null +++ b/playbooks/cleanup.yml @@ -0,0 +1,18 @@ +--- +- hosts: localhost + connection: local + become: no + gather_facts: false + vars_files: + - ansible/config.yml + vars: + provision_action: destroy + roles: + - local.provision + +- hosts: localhost + connection: local + become: no + gather_facts: false + roles: + - local.clean diff --git a/playbooks/environment.sh b/playbooks/environment.sh index a0b257c3..b19731be 100644 --- a/playbooks/environment.sh +++ b/playbooks/environment.sh @@ -1,3 +1,3 @@ # source me -export ANSIBLE_INVENTORY=.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory +export ANSIBLE_INVENTORY=site_inventory diff --git a/playbooks/local.yml b/playbooks/local.yml index 1f44718b..e7483239 100644 --- a/playbooks/local.yml +++ b/playbooks/local.yml @@ -2,7 +2,8 @@ - hosts: localhost connection: local become: no + vars: + provision_action: create roles: - local.defaults - - local.vagrant - - local.prep + - local.provision diff --git a/playbooks/roles/config.collect/tasks/main.yml b/playbooks/roles/config.collect/tasks/main.yml index f9a5239b..e6d72396 100644 --- a/playbooks/roles/config.collect/tasks/main.yml +++ b/playbooks/roles/config.collect/tasks/main.yml @@ -12,6 +12,7 @@ - name: Copy test configuration data shell: cp /root/test-info.yml {{ config.configdir }} when: inventory_hostname in groups['clients'] + ignore_errors: true - name: Copy configuration directory synchronize: diff --git a/playbooks/roles/local.clean/tasks/main.yml b/playbooks/roles/local.clean/tasks/main.yml new file mode 100644 index 00000000..65cd988e --- /dev/null +++ b/playbooks/roles/local.clean/tasks/main.yml @@ -0,0 +1,7 @@ +--- +- name: Delete generated files + file: + path: "{{ item }}" + state: absent + with_items: + - ansible/config.yml diff --git a/playbooks/roles/local.defaults/tasks/main.yml b/playbooks/roles/local.defaults/tasks/main.yml index 6949d908..0822ba38 100644 --- a/playbooks/roles/local.defaults/tasks/main.yml +++ b/playbooks/roles/local.defaults/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: Load settings + include_vars: + file: "settings.yml" + - name: Generate config.yml in ansible directory template: src: config.yml.j2 @@ -7,6 +11,8 @@ os: "{{ use_distro | default('centos9') }}" be: "{{ (backend | default('glusterfs') | split('.'))[0] }}" variant: "{{ (backend | default('glusterfs') | split('.'))[1] | default('default') }}" + max_memory: "{{ ansible_memfree_mb }}" + max_cpu: "{{ ansible_processor_nproc }}" - name: Load configuration include_vars: diff --git a/playbooks/roles/local.defaults/templates/config.yml.j2 b/playbooks/roles/local.defaults/templates/config.yml.j2 index 57feed36..6b488d0b 100644 --- a/playbooks/roles/local.defaults/templates/config.yml.j2 +++ b/playbooks/roles/local.defaults/templates/config.yml.j2 @@ -10,11 +10,6 @@ config: - "{{ os_info[os_name].distro }}{{ os_info[os_name].version}}.yml" - "{{ os_info[os_name].distro }}.yml" - "{{ os_info[os_name].family }}.yml" - vagrant: - {%- if vagrant.pool is defined +%} - pool: "{{ vagrant.pool }}" - {%- endif +%} - image: "{{ vagrant.images[os_name] }}" {%- endfor +%} be: @@ -25,23 +20,69 @@ config: tests: {{ tests }} + provisioners: + {%- for prov in environments[be].nodes | dict2items | map(attribute='value.provisioner', default='vagrant') | unique +%} + {{ prov }}: + {%- for item in provisioners[prov] | default({}) +%} + {{ item }}: {{ provisioners[prov][item] }} + {%- endfor +%} + hosts: + {%- for name in environments[be].nodes +%} + {%- set data = environments[be].nodes[name] +%} + {%- if data.provisioner | default(environments[be].provisioner | default('vagrant')) == prov +%} + {%- for idx in range(data.instances | default(1)) +%} + - {{ name }}{{ idx }} + {%- endfor +%} + {%- endif +%} + {%- endfor +%} + {%- endfor +%} + +{%- set total_mem = max_memory * ((memory | default(resources.memory | default(50))) | int) / 100 +%} +{%- set total_cpu = max_cpu * ((cpu | default(resources.cpu | default(100))) | int) / 100 +%} +{%- set extra_mem = 0 +%} +{%- set extra_cpu = 0 +%} +{%- set base_mem = [] +%} +{%- set base_cpu = [] +%} +{%- set weight_mem = [] +%} +{%- set weight_cpu = [] +%} +{%- for name in environments[be].nodes +%} +{%- set data = environments[be].nodes[name] +%} +{%- set count = data.instances | default(1) +%} +{%- set _ = base_mem.append(count * (data.memory | default(environments[be].memory))) +%} +{%- set _ = base_cpu.append(count * (data.cpus | default(environments[be].cpus))) +%} +{%- set _ = weight_mem.append(count * (data.memory_weight | default(1))) +%} +{%- set _ = weight_cpu.append(count * (data.cpu_weight | default(1))) +%} +{%- endfor +%} +{%- set base_mem = base_mem | sum +%} +{%- set base_cpu = base_cpu | sum +%} +{%- set weight_mem = weight_mem | sum +%} +{%- set weight_cpu = weight_cpu | sum +%} +{%- if weight_mem > 0 +%} +{%- set extra_mem = ([ total_mem - base_mem, 0] | max) / weight_mem / 1024 +%} +{%- endif +%} +{%- if weight_cpu > 0 +%} +{%- set extra_cpu = ([ total_cpu - base_cpu, 0] | max) / weight_cpu +%} +{%- endif +%} + nodes: {%- for name in environments[be].nodes +%} {%- set data = environments[be].nodes[name] +%} + {%- set prov = data.provisioner | default(environments[be].provisioner | default('vagrant')) +%} {%- for idx in range(data.instances | default(1)) +%} {{ name }}{{ idx }}: groups: {{ data.groups }} + provisioner: {{ prov }} os: {{ data.os | default(environments[be].os | default(os)) }} - cpus: {{ data.cpus | default(environments[be].cpus) }} - memory: {{ data.memory | default(environments[be].memory) }} + cpus: {{ (data.cpus | default(environments[be].cpus)) + ((extra_cpu * (data.cpu_weight | default(1))) | int) }} + memory: {{ (data.memory | default(environments[be].memory)) + 1024 * ((extra_mem * (data.memory_weight | default(1))) | int) }} disks: {{ data.disks | default([]) }} networks: {%- for net in data.networks | default({}) +%} - {{ net }}: {{ vagrant.networks[net] | ansible.utils.ipaddr(data.networks[net] + idx) | ansible.utils.ipaddr('address') }} + {{ net }}: {{ provisioners[prov].networks[net] | ansible.utils.ipaddr(data.networks[net] + idx) | ansible.utils.ipaddr('address') }} {%- endfor +%} ctdb: {%- for net in data.ctdb | default({}) +%} - {{ net }}: {{ vagrant.networks[net] | ansible.utils.ipaddr(data.ctdb[net] + idx) | ansible.utils.ipaddr('address') }} + {{ net }}: {{ provisioners[prov].networks[net] | ansible.utils.ipaddr(data.ctdb[net] + idx) | ansible.utils.ipaddr('address') }} {%- endfor +%} {%- endfor +%} {%- endfor +%} @@ -56,5 +97,5 @@ config: {%- endfor +%} {%- endfor +%} - statedir: "{{ misc.host.statedir }}/sit.{{ be }}_statedump" + statedir: "{{ misc.host.statedir }}/sit.{{ backend }}_statedump" configdir: "{{ misc.host.configdir }}" diff --git a/playbooks/roles/local.provision/tasks/main.yml b/playbooks/roles/local.provision/tasks/main.yml new file mode 100644 index 00000000..b2d757cb --- /dev/null +++ b/playbooks/roles/local.provision/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- name: Provision all machines + include_role: + name: "provisioner.{{ provisioner_name }}" + tasks_from: "{{ provision_action }}/main.yml" + vars: + data: "{{ config.provisioners[provisioner_name] }}" + loop: "{{ config.provisioners.keys() }}" + loop_control: + loop_var: provisioner_name diff --git a/playbooks/roles/local.vagrant/tasks/main.yml b/playbooks/roles/local.vagrant/tasks/main.yml deleted file mode 100644 index 7e38e407..00000000 --- a/playbooks/roles/local.vagrant/tasks/main.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- set_fact: - host_os: "{{ ansible_distribution }}" - host_os_version: "{{ ansible_distribution_major_version }}" - -- name: Setup Vagrant file - template: - src: Vagrantfile.j2 - dest: Vagrantfile - -- name: start vagrant vms - command: vagrant up --no-provision - -- name: provision vagrant vms - command: vagrant provision diff --git a/playbooks/roles/local.prep/tasks/main.yml b/playbooks/roles/provisioner.vagrant/tasks/create/main.yml similarity index 74% rename from playbooks/roles/local.prep/tasks/main.yml rename to playbooks/roles/provisioner.vagrant/tasks/create/main.yml index 36b62391..577de3a7 100644 --- a/playbooks/roles/local.prep/tasks/main.yml +++ b/playbooks/roles/provisioner.vagrant/tasks/create/main.yml @@ -1,26 +1,37 @@ --- +- name: Setup Vagrant file + template: + src: Vagrantfile.j2 + dest: Vagrantfile + +- name: start vagrant vms + command: vagrant up --no-provision + +- name: provision vagrant vms + command: vagrant provision + - name: copy vagrant generated inventory file - local machine copy: src: .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory - dest: ./vagrant_ansible_inventory + dest: ./site_inventory - name: adapt inventory - ssh options blockinfile: - path: ./vagrant_ansible_inventory + path: ./site_inventory block: | [all:vars] ansible_ssh_common_args='-o StrictHostKeyChecking=no' - name: copy vagrant generated inventory file - setup machine copy: - src: ./vagrant_ansible_inventory - dest: ./ansible/vagrant_ansible_inventory + src: ./site_inventory + dest: ./ansible/site_inventory - name: adapt inventory - correct ssh key replace: - path: ./ansible/vagrant_ansible_inventory + path: ./ansible/site_inventory regexp: "ansible_ssh_private_key_file='.*/\\.vagrant\\.d/insecure_private_key'" - replace: "ansible_ssh_private_key_file='/home/vagrant/ansible/vagrant_insecure_private_ssh_key'" + replace: "ansible_ssh_private_key_file='insecure_private_ssh_key'" - name: dump ssh config command: vagrant ssh-config @@ -48,7 +59,7 @@ replace: path: ./ansible/ssh-config-setup regexp: "IdentityFile .*" - replace: "IdentityFile /home/vagrant/ansible/vagrant_insecure_private_ssh_key" + replace: "IdentityFile ansible/insecure_private_ssh_key" - name: Create state directory structure on host file: diff --git a/playbooks/roles/provisioner.vagrant/tasks/destroy/main.yml b/playbooks/roles/provisioner.vagrant/tasks/destroy/main.yml new file mode 100644 index 00000000..ae8618b1 --- /dev/null +++ b/playbooks/roles/provisioner.vagrant/tasks/destroy/main.yml @@ -0,0 +1,15 @@ +--- +- name: Destroy vagrant machines + command: vagrant destroy -f + +- name: Remove vagrant settings + file: + path: "{{ item }}" + state: absent + with_items: + - .vagrant + - Vagrantfile + - ansible/site_inventory + - ansible/ssh-config-setup + - site_inventory + - ssh-config-host diff --git a/playbooks/templates/Vagrantfile.j2 b/playbooks/roles/provisioner.vagrant/templates/Vagrantfile.j2 similarity index 71% rename from playbooks/templates/Vagrantfile.j2 rename to playbooks/roles/provisioner.vagrant/templates/Vagrantfile.j2 index 4a7bd39f..f5b3b12f 100644 --- a/playbooks/templates/Vagrantfile.j2 +++ b/playbooks/roles/provisioner.vagrant/templates/Vagrantfile.j2 @@ -4,9 +4,8 @@ Vagrant.configure("2") do |config| config.ssh.insert_key = false - config.vm.provider :libvirt do |v,override| - override.vm.synced_folder '.', '/vagrant', disabled: true - + config.vm.synced_folder '.', '/vagrant', disabled: true + config.vm.provider :libvirt do |v| # We can not use qemu_use_session universally. See section "Upgrade/compatibility impact" # from the following Fedora doc: # https://fedoraproject.org/wiki/Changes/Vagrant_2.2_with_QEMU_Session @@ -21,32 +20,32 @@ Vagrant.configure("2") do |config| # https://github.com/heketi/heketi/pull/1008 v.cpu_mode = 'host-passthrough' end -{% for node in config.nodes %} - {%- set data = config.nodes[node] %} +{% for host in data.hosts %} + {%- set node = config.nodes[host] %} {%- set vm_idx = loop.index0 +%} - config.vm.define "{{ node }}" do |node| - node.vm.box = "{{ config.os[data.os].vagrant.image }}" - node.vm.hostname = "{{ node }}" - {%- for net in data.networks +%} - node.vm.network :private_network, ip: "{{ data.networks[net] }}" + config.vm.define "{{ host }}" do |node| + node.vm.box = "{{ provisioners[node.provisioner].images[node.os] }}" + node.vm.hostname = "{{ host }}" + {%- for net in node.networks +%} + node.vm.network :private_network, ip: "{{ node.networks[net] }}" {%- endfor +%} node.vm.provider :virtualbox do |vb| - {%- for size in data.disks +%} + {%- for size in node.disks +%} vb.customize [ "createhd", "--filename", "disk-{{ vm_idx }}{{ loop.index0 }}.vdi", "--size", {{ size * 1024 }} ] vb.customize [ "storageattach", :id, "--storagectl", "SATA Controller", "--port", {{ loop.index0 + 3 }}, "--device", 0, "--type", "hdd", "--medium", "disk-{{ vm_idx }}{{ loop.index0 }}.vdi" ] {%- endfor +%} - vb.memory = {{ data.memory }} - vb.cpus = {{ data.cpus }} + vb.memory = {{ node.memory }} + vb.cpus = {{ node.cpus }} end node.vm.provider :libvirt do |lv| - {%- if config.os[data.os].vagrant.pool is defined +%} - lv.storage_pool_name = "{{ config.os[data.os].vagrant.pool }}" + {%- if data.pool is defined +%} + lv.storage_pool_name = "{{ data.pool }}" {%- endif +%} - {%- for size in data.disks +%} + {%- for size in node.disks +%} lv.storage :file, :device => "vd{{ "bcdefghijklmnopqrstuvwxyz"[loop.index0] }}", :path => "disk-{{ vm_idx }}{{ loop.index0 }}.disk", :size => '{{ size }}G' {%- endfor +%} - lv.memory = {{ data.memory }} - lv.cpus = {{ data.cpus }} + lv.memory = {{ node.memory }} + lv.cpus = {{ node.cpus }} end {%- if loop.last +%} diff --git a/playbooks/roles/setup.prep/tasks/main.yml b/playbooks/roles/setup.prep/tasks/main.yml index 340d7668..4fad845c 100644 --- a/playbooks/roles/setup.prep/tasks/main.yml +++ b/playbooks/roles/setup.prep/tasks/main.yml @@ -11,29 +11,21 @@ name: 'sit.{{ config.be.name }}' tasks_from: setup/main.yml -- name: copy ansible playbooks to setup machine - synchronize: - src: ansible/ - dest: /home/vagrant/ansible +- name: Prepare configuration files + become: false + block: + - name: copy ansible playbooks to setup machine + synchronize: + src: ansible/ + dest: ansible -- name: ensure permissions on ssh key file - file: - path: /home/vagrant/ansible/vagrant_insecure_private_ssh_key - mode: u=rw,g=,o= - owner: vagrant - group: vagrant + - name: ensure permissions on ssh key file + file: + path: ansible/insecure_private_ssh_key + mode: u=rw,g=,o= -- name: change ownership of ansible directory and files - file: - path: /home/vagrant/ansible - owner: vagrant - group: vagrant - recurse: yes - -- name: copy ssh config in place - copy: - src: ansible/ssh-config-setup - dest: /home/vagrant/.ssh/config - mode: 0600 - owner: vagrant - group: vagrant + - name: copy ssh config in place + copy: + src: ansible/ssh-config-setup + dest: .ssh/config + mode: 0600 diff --git a/playbooks/roles/setup.test/tasks/main.yml b/playbooks/roles/setup.test/tasks/main.yml index c7282212..97c79ac8 100644 --- a/playbooks/roles/setup.test/tasks/main.yml +++ b/playbooks/roles/setup.test/tasks/main.yml @@ -1,5 +1,6 @@ --- - name: test playbook node connectivity on the setup machine - command: >- - ansible-playbook -i /home/vagrant/ansible/vagrant_ansible_inventory - /home/vagrant/ansible/test.local.yml + command: + chdir: ansible + cmd: >- + ansible-playbook -i site_inventory test.local.yml diff --git a/playbooks/roles/sit.xfs/tasks/config/main.yml b/playbooks/roles/sit.xfs/tasks/config/main.yml index ed97d539..74fef69d 100644 --- a/playbooks/roles/sit.xfs/tasks/config/main.yml +++ b/playbooks/roles/sit.xfs/tasks/config/main.yml @@ -1 +1,7 @@ --- +- name: Copy necessary configuration directories + shell: cp -r {{ item }} {{ config.configdir }} + with_items: + - /etc/samba + - /etc/ctdb + when: inventory_hostname in groups['cluster'] diff --git a/playbooks/roles/local.defaults/vars/main.yml b/playbooks/settings.yml similarity index 50% rename from playbooks/roles/local.defaults/vars/main.yml rename to playbooks/settings.yml index 3acc69c6..100514b9 100644 --- a/playbooks/roles/local.defaults/vars/main.yml +++ b/playbooks/settings.yml @@ -13,47 +13,88 @@ os_info: distro: centos version: 9 -# Vagrant/VM global settings -vagrant: - # Vagrant image to use per OS - images: - centos8: generic/centos8s - centos9: generic/centos9s - - # Available networks for the VMs - networks: - private: 192.168.122.0/24 - public: 192.168.123.0/24 - -# # Storage pool to use for the virtual disks (optional) -# pool: data - misc: host: statedir: "/tmp" configdir: "/tmp/config" +resources: + # Percentage of free memory that will be used for sit-environment by default. + # It can be overriden by setting the `memory` extra variable. + # + # All VMs are guaranteed to use the minimum memory defined, even if this + # makes them use more than the amount of memory defined here. + # + # The actual amount of memory assigned to each VM is computed by dynamically + # distributing the portion of the free memory assigned to sit-environment + # proportionally based on the memory weight of each VM. + # + # B: Sum of the minimum memory assigned to each VM. + # T: Sum of the weights assigned to each VM. + # G: Total available memory to sit-environment, which is equal to the total + # free memory multiplied by the defined percentage. + # Mi: Total memory assigned to i-th VM. + # mi: Minimum memory assigned to i-th VM. + # wi: Weight assigned to i-th VM. + # + # Mi = mi + int(max(G - B, 0) * wi / T) + # + # Examples with 50% memory utilization and 1 GiB minimum: + # + # Weight 58 GiB Free 38 GiB Free 18 GiB Free 8 GiB Free + # setup0: 0 1 GiB 1 GiB 1 GiB 1 GiB + # client0: 1 6 GiB 4 GiB 2 GiB 1 GiB + # storage0: 2 11 GiB 7 GiB 3 GiB 1 GiB + # storage1: 2 11 GiB 7 GiB 3 GiB 1 GiB + memory: 50 + + # Percentage of the cores that will be used for sit-environment by default. + # It can be overriden by setting the `cpu` extra variable. + # + # This is equivalent to the `memory` option but applied to CPU cores. + # + # It's allowed to use a value higher than 100% assuming that some VMs will + # actually not use all the cores at 100%. + cpu: 100 + # List of tests to run tests: - sit-test-cases +provisioners: + vagrant: + images: + centos8: generic/centos8s + centos9: generic/centos9s + + networks: + private: 192.168.122.0/24 + public: 192.168.123.0/24 + +# # Storage pool to use for the virtual disks (optional) +# pool: data + # The `environments` object contains one entry for each defined backend, # which specifies the types of VMs to create, the amount of each one, and # the resources they need. # # Each environment has the following properties: # +# provisioner: (optional, default: 'vagrant') +# Default provisioner used to provision the hosts of the environment. +# This value can be overriden by specific VM type definitions. +# # os: (optional, default: `use_distro` if defined, 'centos9' otherwise) # Default OS installed on all hosts of the environment. This value can # be overriden by specific VM type definitions. # # cpus: (required) -# Default number of CPUs to assign to each VM. This value can be +# Default minimum number of CPUs to assign to each VM. This value can be # overridden by specific VM type definitions. # # memory: (required) -# Default amount of memory (in MiB) assigned to each VM. This value -# can be overridden by specific VM type definitions. +# Default minimum amount of memory (in MiB) assigned to each VM. This +# value can be overridden by specific VM type definitions. # # data: (optional, default: {}) # This field contains any extra data specific to the environment that @@ -68,6 +109,10 @@ tests: # # Each defined node type has the following properties: # +# provisioner: (optional, default: the value of `provisioner` in the +# environment) +# Provisioner used to provision this VM type. +# # os: (optional, default: the value of `os` in the environment) # OS installed on this VM type. # @@ -75,10 +120,22 @@ tests: # Defines how many VMs of this type will be created. # # cpus: (optional, default: the value of `cpus` in the environment) -# Number of CPUs for this specific VM type. +# Minimum number of CPUs for this specific VM type. +# +# cpu_weight: (optional, default: 1) +# Relative weight of the number of CPUs assigned to this VM type. A higher +# weight will assign more CPUs to this VM type. A value of 0 will use just +# the minimum number of CPUs defined by the `cpus` option. See the comment +# in the `resources` section to see how this value works. # # memory: (optional, default: the value of `memory` in the environment) -# Amount of memory for this specific VM type. +# Minimum amount of memory for this specific VM type. +# +# memory_weight: (optional, default: 1) +# Relative weight of the memory assigned to this VM type. A higher weight +# will assign more memory to this VM type. A value of 0 will use just the +# minimum memory defined by the `memory` option. See the comment in the +# `resources` section to see how this value works. # # disks: (optional, default: []) # List of additional disks for this type of VM (besides the system @@ -106,18 +163,24 @@ environments: nodes: setup: + cpu_weight: 0 + memory_weight: 0 networks: private: 200 groups: [admin] os: centos8 client: + cpu_weight: 1 + memory_weight: 1 networks: public: 5 groups: [clients] storage: instances: 2 + cpu_weight: 2 + memory_weight: 2 disks: [10, 10, 10] networks: private: 100 @@ -133,11 +196,15 @@ environments: nodes: setup: + cpu_weight: 0 + memory_weight: 0 networks: private: 200 groups: [admin] storage: + cpu_weight: 1 + memory_weight: 1 disks: [10] networks: private: 100 @@ -147,6 +214,8 @@ environments: groups: [cluster] client: + cpu_weight: 1 + memory_weight: 1 networks: public: 5 groups: [clients] @@ -160,12 +229,16 @@ environments: nodes: setup: + cpu_weight: 0 + memory_weight: 0 networks: private: 200 groups: [admin] storage: instances: 3 + cpu_weight: 2 + memory_weight: 2 disks: [10, 10, 10] networks: private: 100 @@ -175,6 +248,8 @@ environments: groups: [cluster] client: + cpu_weight: 1 + memory_weight: 1 networks: public: 5 groups: [clients]