From: David Galloway Date: Tue, 10 Oct 2017 18:27:08 +0000 (-0400) Subject: ansible: Support centos static libvirt slaves X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ff5ee779f11e4f0013713a3fe128199ced05e8d8;p=ceph-build.git ansible: Support centos static libvirt slaves Signed-off-by: David Galloway --- diff --git a/ansible/examples/slave_libvirt_static.yml b/ansible/examples/slave_libvirt_static.yml index 2edd2279..58818f56 100644 --- a/ansible/examples/slave_libvirt_static.yml +++ b/ansible/examples/slave_libvirt_static.yml @@ -1,6 +1,6 @@ --- # This playbook is used to configure static libvirt&&vagrant slaves. -# Ubuntu Xenial or Yakkety are the only supported distros at this time +# Ubuntu >= 16.04 and CentOS 7.3 are the only tested distros # # Example usage: # On a baremetal node already configured by the github.com/ceph/ceph-cm-ansible common role, @@ -21,26 +21,26 @@ tasks: - - name: Fail if slave is not running Xenial or Yakkety - fail: - msg: "Slave is not running Xenial or Yakkety" - when: ansible_distribution != "Ubuntu" or - (ansible_distribution == "Ubuntu" and ansible_distribution_major_version < 16) - + ### REPO TASKS ### - name: Check for custom repos shell: "ls -1 /etc/apt/sources.list.d" register: custom_repos + when: ansible_os_family == "Debian" - name: Delete custom repos file: path: "/etc/apt/sources.list.d/{{ item }}" state: absent with_items: "{{ custom_repos.stdout_lines }}" - when: custom_repos|length > 0 + when: + - custom_repos|length > 0 + - custom_repos is defined + - ansible_os_family == "Debian" - name: Update apt cache apt: update_cache: yes + when: ansible_os_family == "Debian" # vagrant doesn't have repositories, this chacra repo will be better to have # around and can get updates as soon as a new vagrant version is published via @@ -49,10 +49,29 @@ apt_repository: repo: "deb [trusted=yes] https://chacra.ceph.com/r/vagrant/latest/HEAD/ubuntu/xenial/flavors/default/ xenial main" state: present + when: ansible_os_family == "Debian" + + - name: add the vagrant repository + yum_repository: + name: vagrant + description: self-hosted vagrant repo + baseurl: https://chacra.ceph.com/r/vagrant/latest/HEAD/centos/7/flavors/default/x86_64/ + enabled: yes + gpgcheck: no + when: ansible_os_family == "RedHat" + - name: disable epel + lineinfile: + path: "/etc/yum.repos.d/epel.repo" + regexp: '^enabled=.*' + line: 'enabled=0' + when: ansible_os_family == "RedHat" + + ### PACKAGING TASKS ### - name: Update apt cache apt: update_cache: yes + when: ansible_os_family == "Debian" - name: Install required packages apt: @@ -74,7 +93,45 @@ - vagrant - default-jdk - default-jre + when: ansible_os_family == "Debian" + + - name: install requirements without epel + yum: + name: "{{ item }}" + state: present + disablerepo: epel + update_cache: yes + with_items: + - git + - gcc + - python-devel + - libffi-devel + - java-1.8.0-openjdk-devel + - qemu-kvm + - libvirt-devel + - libguestfs + - libvirt + - libguestfs-tools + - vagrant + - wget + - curl + - python-virtualenv + - openssl-devel + - redhat-lsb-core + when: ansible_os_family == "RedHat" + - name: install packages from epel + yum: + name: "{{ item }}" + state: present + enablerepo: epel + update_cache: yes + with_items: + - jq + - python-pip + when: ansible_os_family == "RedHat" + + ### COMMON TASKS ### - set_fact: jenkins_group: 'libvirtd' when: ansible_distribution_version == '16.04' @@ -82,7 +139,8 @@ - set_fact: jenkins_group: 'libvirt' when: (ansible_distribution_version == '16.10') or - (ansible_distribution_major_version >= 17) + (ansible_distribution_major_version >= 17) or + (ansible_os_family == "RedHat") - name: "create a {{ jenkins_user }} user" user: @@ -203,16 +261,34 @@ # github.com.pub is the output of `ssh-keyscan github.com` key: "{{ lookup('file', 'files/ssh/hostkeys/github.com.pub') }}" - - name: start the libvirt-bin service + ### LIBVIRT TASKS ### + - name: "configure libvirt permissions for {{ jenkins_user }}" + blockinfile: + dest: /etc/libvirt/qemu.conf + block: | + user = "{{ jenkins_user }}" + group = "{{ jenkins_user }}" + when: ansible_os_family == "RedHat" + + - name: start DEB libvirt services service: - name: libvirt-bin - state: started + name: "{{ item }}" + state: restarted + with_items: + - libvirt-bin + - libvirt-guests + when: ansible_os_family == "Debian" - - name: start the libvirt-guests service + - name: start RPM libvirt services service: - name: libvirt-guests - state: started + name: "{{ item }}" + state: restarted + with_items: + - libvirtd + - libvirt-guests + when: ansible_os_family == "RedHat" + ### JENKINS TASKS ### - name: register the new slave to jenkins master with jnlp jenkins_node: username: "{{ api_user }}" diff --git a/scripts/build_utils.sh b/scripts/build_utils.sh index 42984815..06f71700 100644 --- a/scripts/build_utils.sh +++ b/scripts/build_utils.sh @@ -436,7 +436,12 @@ clear_libvirt_networks() { restart_libvirt_services() { # restart libvirt services - sudo service libvirt-bin restart + get_distro_and_target + if [ "$DISTRO" == "rhel" ] || [ "$DISTRO" == "centos" ]; then + sudo service libvirtd restart + else + sudo service libvirt-bin restart + fi sudo service libvirt-guests restart }