From 27b4fbf163a18018a93f7d1ba942073f3f777e68 Mon Sep 17 00:00:00 2001 From: Ivan Grynenko Date: Sun, 12 Jun 2016 19:18:25 +1000 Subject: [PATCH] Squashed 'lemp-rhel7/roles/ansible-role-git/' content from commit b4f85aa git-subtree-dir: lemp-rhel7/roles/ansible-role-git git-subtree-split: b4f85aa9ad5368def602809847ef0367bbb407f9 --- .gitignore | 1 + .travis.yml | 84 +++++++++++++++++++++++++++++++++++ README.md | 55 +++++++++++++++++++++++ defaults/main.yml | 23 ++++++++++ meta/main.yml | 22 +++++++++ tasks/install-from-source.yml | 62 ++++++++++++++++++++++++++ tasks/main.yml | 23 ++++++++++ tests/Dockerfile.centos-6 | 15 +++++++ tests/Dockerfile.centos-7 | 27 +++++++++++ tests/Dockerfile.ubuntu-12.04 | 11 +++++ tests/Dockerfile.ubuntu-14.04 | 11 +++++ tests/test-package.yml | 14 ++++++ tests/test-source.yml | 15 +++++++ vars/main.yml | 2 + 14 files changed, 365 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/install-from-source.yml create mode 100644 tasks/main.yml create mode 100644 tests/Dockerfile.centos-6 create mode 100644 tests/Dockerfile.centos-7 create mode 100644 tests/Dockerfile.ubuntu-12.04 create mode 100644 tests/Dockerfile.ubuntu-14.04 create mode 100644 tests/test-package.yml create mode 100644 tests/test-source.yml create mode 100644 vars/main.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b066709 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.LSOverride diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a221fcc --- /dev/null +++ b/.travis.yml @@ -0,0 +1,84 @@ +--- +sudo: required + +env: + # Only test source install on latest supported OSes. + # - distribution: centos + # version: 7 + # init: /usr/lib/systemd/systemd + # run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + # SITE: source + # GIT_VERSION: 2.7.1 + - distribution: ubuntu + version: 14.04 + init: /sbin/init + run_opts: "" + SITE: source + GIT_VERSION: 2.7.1 + + # Test package install on all supported OSes. + - distribution: centos + version: 6 + init: /sbin/init + run_opts: "" + SITE: package + GIT_VERSION: 1.7.1 + - distribution: centos + version: 7 + init: /usr/lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + SITE: package + GIT_VERSION: 1.8.3.1 + - distribution: ubuntu + version: 14.04 + init: /sbin/init + run_opts: "" + SITE: package + GIT_VERSION: 1.9.1 + - distribution: ubuntu + version: 12.04 + init: /sbin/init + run_opts: "" + SITE: package + GIT_VERSION: 1.7.9.5 + +services: + - docker + +before_install: + # - sudo apt-get update + # Pull container + - 'sudo docker pull ${distribution}:${version}' + # Customize container + - 'sudo docker build --rm=true --file=tests/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests' + +script: + - container_id=$(mktemp) + # Run container in detached state + - 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"' + + # Ansible syntax check. + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test-${SITE}.yml --syntax-check' + + # Test role. + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test-${SITE}.yml' + + # Test role idempotence. + - > + sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test-${SITE}.yml + | grep -q 'changed=0.*failed=0' + && (echo 'Idempotence test: pass' && exit 0) + || (echo 'Idempotence test: fail' && exit 1) + + # Ensure Git is installed and at the right version. + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm which git' + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm test -x /usr/bin/git' + + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm git --version' + - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm /usr/bin/git --version | grep -qF "$GIT_VERSION"' + + # Clean up + - 'sudo docker stop "$(cat ${container_id})"' + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e7b6676 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# Ansible Role: Git + +[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-git.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-git) + +Installs Git, a distributed version control system, on any RHEL/CentOS or Debian/Ubuntu Linux system. + +## Requirements + +None. + +## Role Variables + +Available variables are listed below, along with default values (see `defaults/main.yml`): + + workspace: /root + +Where certain files will be downloaded and adjusted prior to git installation, if needed. + + git_enablerepo: "" + +This variable, a well as `git_packages`, will be used to install git via a particular `yum` repo if `git_install_from_source` is false (CentOS only). Any additional repositories you have installed that you would like to use for a newer/different Git version. + + git_packages: + - git + - git-svn + +The specific Git packages that will be installed. By default, `git-svn` is included, but you can easily add this variable to your playbook's variables and remove `git-svn` if desired. + + git_install_from_source: false + git_install_path: "/usr" + git_version: "2.1.0" + +Whether to install Git from source; if set to `true`, `git_version` is required and will be used to install a particular version of git (see all available versions here: https://www.kernel.org/pub/software/scm/git/), and `git_install_path` defines where git should be installed. + + git_install_from_source_force_update: false + +If git is already installed at and older version, force a new source build. Only applies if `git_install_from_source` is `true`. + +## Dependencies + +None. + +## Example Playbook + + - hosts: servers + roles: + - { role: geerlingguy.git } + +## License + +MIT / BSD + +## Author Information + +This role was created in 2014 by [Jeff Geerling](http://jeffgeerling.com/), author of [Ansible for DevOps](http://ansiblefordevops.com/). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..7c64bc2 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,23 @@ +--- +workspace: /root + +# If git_install_from_source is set to false, these two variables define whether +# to use an additional repo for the package installation, and which git packages +# will be installed. +git_enablerepo: "" +git_packages: + - git + - git-svn + +# If set to TRUE, git will be installed from source, using the version set with +# the 'git_version' variable instead of using a package. +git_install_from_source: false +git_install_path: "/usr" +git_version: "2.7.1" + +# If git is already installed at and older version, force a new source build. +# Only applies if git_install_from_source is `true`. +git_install_from_source_force_update: false + +# Leave this at it's default. +git_reinstall_from_source: false diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..d119d20 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,22 @@ +--- +dependencies: [] + +galaxy_info: + author: geerlingguy + description: Git version control software + company: "Midwestern Mac, LLC" + license: "license (BSD, MIT)" + min_ansible_version: 1.9 + platforms: + - name: EL + versions: + - all + - name: Debian + versions: + - all + - name: Ubuntu + versions: + - all + galaxy_tags: + - development + - system diff --git a/tasks/install-from-source.yml b/tasks/install-from-source.yml new file mode 100644 index 0000000..3dc0458 --- /dev/null +++ b/tasks/install-from-source.yml @@ -0,0 +1,62 @@ +--- +- name: Ensure git's dependencies are installed (RedHat). + yum: "pkg={{ item }} state=installed" + with_items: + - gettext-devel + - expat-devel + - curl-devel + - zlib-devel + - perl-devel + - openssl-devel + - subversion-perl + - make + - gcc + when: ansible_os_family == 'RedHat' + +- name: Ensure git's dependencies are installed (Debian). + apt: "pkg={{ item }} state=installed" + with_items: + - libcurl4-gnutls-dev + - libexpat1-dev + - gettext + - libssl-dev + - build-essential + - gcc + when: ansible_os_family == 'Debian' + +- name: Get installed version + command: git --version + changed_when: false + failed_when: false + # Ansible 1.8 feature. + # warn: no + register: git_installed_version + +- name: Force git install if the version numbers do not match + set_fact: + git_reinstall_from_source: true + when: 'git_install_from_source_force_update and (git_installed_version|success and (git_installed_version.stdout | regex_replace("^.*?([0-9\.]+)$", "\\1") | version_compare(git_version, operator="!=")))' + +- name: Download git. + get_url: + url: "https://www.kernel.org/pub/software/scm/git/git-{{ git_version }}.tar.gz" + dest: "{{ workspace }}/git-{{ git_version }}.tar.gz" + when: git_installed_version|failed or git_reinstall_from_source + +- name: Expand git archive. + unarchive: + src: "{{ workspace }}/git-{{ git_version }}.tar.gz" + dest: "{{ workspace }}" + creates: "{{ workspace }}/git-{{ git_version }}/README" + copy: no + when: git_installed_version|failed or git_reinstall_from_source + +- name: Build git. + command: > + make prefix={{ git_install_path }} {{ item }} + chdir={{ workspace }}/git-{{ git_version }} + with_items: + - all + - install + when: git_installed_version|failed or git_reinstall_from_source + become: yes diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..22f2b81 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: Ensure git is installed (RedHat). + yum: + name: "{{ item }}" + state: installed + enablerepo: "{{ git_enablerepo }}" + with_items: "{{ git_packages }}" + when: (git_install_from_source == false) and (ansible_os_family == 'RedHat') + +- name: Update apt cache (Debian). + apt: update_cache=yes cache_valid_time=86400 + when: ansible_os_family == 'Debian' + +- name: Ensure git is installed (Debian). + apt: + name: "{{ item }}" + state: installed + with_items: "{{ git_packages }}" + when: (git_install_from_source == false) and (ansible_os_family == 'Debian') + +# Install git from source when git_install_from_source is true. +- include: install-from-source.yml + when: git_install_from_source == true diff --git a/tests/Dockerfile.centos-6 b/tests/Dockerfile.centos-6 new file mode 100644 index 0000000..4a4e7b8 --- /dev/null +++ b/tests/Dockerfile.centos-6 @@ -0,0 +1,15 @@ +FROM centos:6 + +# Install Ansible +RUN yum -y update; yum clean all; +RUN yum -y install epel-release +RUN yum -y install git ansible sudo +RUN yum clean all + +# Disable requiretty +RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers + +# Install Ansible inventory file +RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts + +CMD ["/usr/sbin/init"] diff --git a/tests/Dockerfile.centos-7 b/tests/Dockerfile.centos-7 new file mode 100644 index 0000000..8aa0654 --- /dev/null +++ b/tests/Dockerfile.centos-7 @@ -0,0 +1,27 @@ +FROM centos:7 + +# Install systemd -- See https://hub.docker.com/_/centos/ +RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs +RUN yum -y update; yum clean all; \ +(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ +rm -f /lib/systemd/system/multi-user.target.wants/*; \ +rm -f /etc/systemd/system/*.wants/*; \ +rm -f /lib/systemd/system/local-fs.target.wants/*; \ +rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ +rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ +rm -f /lib/systemd/system/basic.target.wants/*; \ +rm -f /lib/systemd/system/anaconda.target.wants/*; + +# Install Ansible +RUN yum -y install epel-release +RUN yum -y install git ansible sudo +RUN yum clean all + +# Disable requiretty +RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers + +# Install Ansible inventory file +RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts + +VOLUME ["/sys/fs/cgroup"] +CMD ["/usr/sbin/init"] diff --git a/tests/Dockerfile.ubuntu-12.04 b/tests/Dockerfile.ubuntu-12.04 new file mode 100644 index 0000000..d0c130c --- /dev/null +++ b/tests/Dockerfile.ubuntu-12.04 @@ -0,0 +1,11 @@ +FROM ubuntu:12.04 +RUN apt-get update + +# Install Ansible +RUN apt-get install -y software-properties-common python-software-properties git +RUN apt-add-repository -y ppa:ansible/ansible +RUN apt-get update +RUN apt-get install -y ansible + +# Install Ansible inventory file +RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts diff --git a/tests/Dockerfile.ubuntu-14.04 b/tests/Dockerfile.ubuntu-14.04 new file mode 100644 index 0000000..ca33287 --- /dev/null +++ b/tests/Dockerfile.ubuntu-14.04 @@ -0,0 +1,11 @@ +FROM ubuntu:14.04 +RUN apt-get update + +# Install Ansible +RUN apt-get install -y software-properties-common git +RUN apt-add-repository -y ppa:ansible/ansible +RUN apt-get update +RUN apt-get install -y ansible + +# Install Ansible inventory file +RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts diff --git a/tests/test-package.yml b/tests/test-package.yml new file mode 100644 index 0000000..e76a3e0 --- /dev/null +++ b/tests/test-package.yml @@ -0,0 +1,14 @@ +--- +- hosts: all + + vars: + git_install_from_source: false + git_install_path: /usr/local + + pre_tasks: + - name: Ensure build dependencies are installed (RedHat). + yum: name=which state=present + when: ansible_os_family == 'RedHat' + + roles: + - role_under_test diff --git a/tests/test-source.yml b/tests/test-source.yml new file mode 100644 index 0000000..a31cc4e --- /dev/null +++ b/tests/test-source.yml @@ -0,0 +1,15 @@ +--- +- hosts: all + + vars: + git_install_from_source: true + git_install_from_source_force_update: true + git_version: 2.7.1 + + pre_tasks: + - name: Ensure build dependencies are installed (RedHat). + yum: name=which state=present + when: ansible_os_family == 'RedHat' + + roles: + - role_under_test diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..10e268a --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# This space intentionally left blank.