├── .ansible-lint ├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ ├── release.yml │ └── stale.yml ├── .gitignore ├── .yamllint ├── LICENSE ├── README.md ├── defaults └── main.yml ├── meta └── main.yml ├── molecule └── default │ ├── converge.yml │ ├── molecule.yml │ └── source-install.yml ├── tasks ├── install-from-source.yml └── main.yml └── vars ├── Debian.yml ├── Fedora.yml ├── RedHat.yml └── main.yml /.ansible-lint: -------------------------------------------------------------------------------- 1 | skip_list: 2 | - 'yaml' 3 | - 'role-name' 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | --- 3 | github: geerlingguy 4 | patreon: geerlingguy 5 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: CI 3 | 'on': 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | schedule: 9 | - cron: "0 6 * * 1" 10 | 11 | defaults: 12 | run: 13 | working-directory: 'geerlingguy.git' 14 | 15 | jobs: 16 | 17 | lint: 18 | name: Lint 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Check out the codebase. 22 | uses: actions/checkout@v4 23 | with: 24 | path: 'geerlingguy.git' 25 | 26 | - name: Set up Python 3. 27 | uses: actions/setup-python@v5 28 | with: 29 | python-version: '3.x' 30 | 31 | - name: Install test dependencies. 32 | run: pip3 install yamllint 33 | 34 | - name: Lint code. 35 | run: | 36 | yamllint . 37 | 38 | molecule: 39 | name: Molecule 40 | runs-on: ubuntu-latest 41 | strategy: 42 | matrix: 43 | include: 44 | # See: https://github.com/geerlingguy/docker-rockylinux9-ansible/issues/6 45 | # - distro: rockylinux9 46 | # playbook: converge.yml 47 | - distro: ubuntu2204 48 | playbook: converge.yml 49 | - distro: debian11 50 | playbook: converge.yml 51 | # - distro: rockylinux9 52 | # playbook: source-install.yml 53 | - distro: ubuntu2004 54 | playbook: source-install.yml 55 | 56 | steps: 57 | - name: Check out the codebase. 58 | uses: actions/checkout@v4 59 | with: 60 | path: 'geerlingguy.git' 61 | 62 | - name: Set up Python 3. 63 | uses: actions/setup-python@v5 64 | with: 65 | python-version: '3.x' 66 | 67 | - name: Install test dependencies. 68 | run: pip3 install ansible molecule molecule-plugins[docker] docker 69 | 70 | - name: Run Molecule tests. 71 | run: molecule test 72 | env: 73 | PY_COLORS: '1' 74 | ANSIBLE_FORCE_COLOR: '1' 75 | MOLECULE_DISTRO: ${{ matrix.distro }} 76 | MOLECULE_PLAYBOOK: ${{ matrix.playbook }} 77 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This workflow requires a GALAXY_API_KEY secret present in the GitHub 3 | # repository or organization. 4 | # 5 | # See: https://github.com/marketplace/actions/publish-ansible-role-to-galaxy 6 | # See: https://github.com/ansible/galaxy/issues/46 7 | 8 | name: Release 9 | 'on': 10 | push: 11 | tags: 12 | - '*' 13 | 14 | defaults: 15 | run: 16 | working-directory: 'geerlingguy.git' 17 | 18 | jobs: 19 | 20 | release: 21 | name: Release 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Check out the codebase. 25 | uses: actions/checkout@v4 26 | with: 27 | path: 'geerlingguy.git' 28 | 29 | - name: Set up Python 3. 30 | uses: actions/setup-python@v5 31 | with: 32 | python-version: '3.x' 33 | 34 | - name: Install Ansible. 35 | run: pip3 install ansible-core 36 | 37 | - name: Trigger a new import on Galaxy. 38 | run: >- 39 | ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }} 40 | $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2) 41 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Close inactive issues 3 | 'on': 4 | schedule: 5 | - cron: "55 16 * * 0" # semi-random time 6 | 7 | jobs: 8 | close-issues: 9 | runs-on: ubuntu-latest 10 | permissions: 11 | issues: write 12 | pull-requests: write 13 | steps: 14 | - uses: actions/stale@v8 15 | with: 16 | days-before-stale: 120 17 | days-before-close: 60 18 | exempt-issue-labels: bug,pinned,security,planned 19 | exempt-pr-labels: bug,pinned,security,planned 20 | stale-issue-label: "stale" 21 | stale-pr-label: "stale" 22 | stale-issue-message: | 23 | This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! 24 | 25 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. 26 | close-issue-message: | 27 | This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. 28 | stale-pr-message: | 29 | This pr has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! 30 | 31 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. 32 | close-pr-message: | 33 | This pr has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. 34 | repo-token: ${{ secrets.GITHUB_TOKEN }} 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.retry 2 | */__pycache__ 3 | *.pyc 4 | .cache 5 | 6 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | 4 | rules: 5 | line-length: 6 | max: 160 7 | level: warning 8 | 9 | ignore: | 10 | .github/workflows/stale.yml 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Jeff Geerling 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Role: Git 2 | 3 | [![CI](https://github.com/geerlingguy/ansible-role-git/actions/workflows/ci.yml/badge.svg)](https://github.com/geerlingguy/ansible-role-git/actions/workflows/ci.yml) 4 | 5 | Installs Git, a distributed version control system, on any RHEL/CentOS or Debian/Ubuntu Linux system. 6 | 7 | ## Requirements 8 | 9 | None. 10 | 11 | ## Role Variables 12 | 13 | Available variables are listed below, along with default values (see `defaults/main.yml`): 14 | 15 | workspace: /root 16 | 17 | Where certain files will be downloaded and adjusted prior to git installation, if needed. 18 | 19 | git_enablerepo: "" 20 | 21 | 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. 22 | 23 | git_packages: 24 | - git 25 | 26 | The specific Git packages that will be installed. By default, only `git` is installed, but you could add additional git-related packages like `git-svn` if desired. 27 | 28 | git_install_from_source: false 29 | git_install_path: "/usr" 30 | git_version: "2.26.0" 31 | 32 | 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. 33 | 34 | git_install_from_source_force_update: false 35 | 36 | If git is already installed at and older version, force a new source build. Only applies if `git_install_from_source` is `true`. 37 | 38 | ## Dependencies 39 | 40 | None. 41 | 42 | ## Example Playbook 43 | 44 | - hosts: servers 45 | roles: 46 | - { role: geerlingguy.git } 47 | 48 | ## License 49 | 50 | MIT / BSD 51 | 52 | ## Author Information 53 | 54 | This role was created in 2014 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). 55 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | workspace: /root 3 | 4 | # If git_install_from_source is set to false, these two variables define whether 5 | # to use an additional repo for the package installation, and which git packages 6 | # will be installed. 7 | git_enablerepo: "" 8 | git_packages: 9 | - git 10 | 11 | # If set to TRUE, git will be installed from source, using the version set with 12 | # the 'git_version' variable instead of using a package. 13 | git_install_from_source: false 14 | git_install_path: "/usr" 15 | git_version: "2.26.0" 16 | 17 | # If git is already installed at and older version, force a new source build. 18 | # Only applies if git_install_from_source is `true`. 19 | git_install_from_source_force_update: false 20 | 21 | # Leave this at it's default. 22 | git_reinstall_from_source: false 23 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: [] 3 | 4 | galaxy_info: 5 | role_name: git 6 | author: geerlingguy 7 | description: Git version control software 8 | company: "Midwestern Mac, LLC" 9 | license: "license (BSD, MIT)" 10 | min_ansible_version: 2.10 11 | platforms: 12 | - name: Fedora 13 | versions: 14 | - all 15 | - name: Debian 16 | versions: 17 | - all 18 | - name: Ubuntu 19 | versions: 20 | - all 21 | galaxy_tags: 22 | - development 23 | - system 24 | - git 25 | - vcs 26 | - source 27 | - code 28 | -------------------------------------------------------------------------------- /molecule/default/converge.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | #become: true 5 | 6 | vars: 7 | git_install_from_source: false 8 | git_install_path: /usr/local 9 | 10 | pre_tasks: 11 | - name: Update apt cache. 12 | apt: update_cache=true cache_valid_time=600 13 | when: ansible_os_family == 'Debian' 14 | changed_when: false 15 | 16 | roles: 17 | - role: geerlingguy.git 18 | -------------------------------------------------------------------------------- /molecule/default/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | role_name_check: 1 3 | dependency: 4 | name: galaxy 5 | options: 6 | ignore-errors: true 7 | driver: 8 | name: docker 9 | platforms: 10 | - name: instance 11 | image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux9}-ansible:latest" 12 | command: ${MOLECULE_DOCKER_COMMAND:-""} 13 | volumes: 14 | - /sys/fs/cgroup:/sys/fs/cgroup:rw 15 | cgroupns_mode: host 16 | privileged: true 17 | pre_build_image: true 18 | provisioner: 19 | name: ansible 20 | playbooks: 21 | converge: ${MOLECULE_PLAYBOOK:-converge.yml} 22 | -------------------------------------------------------------------------------- /molecule/default/source-install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | #become: true 5 | 6 | vars: 7 | git_install_from_source: true 8 | git_install_from_source_force_update: true 9 | git_version: "2.26.0" 10 | 11 | pre_tasks: 12 | - name: Update apt cache. 13 | apt: update_cache=true cache_valid_time=600 14 | when: ansible_os_family == 'Debian' 15 | changed_when: false 16 | 17 | roles: 18 | - role: geerlingguy.git 19 | -------------------------------------------------------------------------------- /tasks/install-from-source.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Include OS-specific variables (RedHat). 3 | include_vars: "{{ ansible_os_family }}.yml" 4 | when: 5 | - ansible_os_family == "RedHat" 6 | - ansible_distribution != "Fedora" 7 | 8 | - name: Include OS-specific variables (Fedora). 9 | include_vars: "{{ ansible_distribution }}.yml" 10 | when: ansible_distribution == "Fedora" 11 | 12 | - name: Include OS-specific variables (Debian). 13 | include_vars: "{{ ansible_os_family }}.yml" 14 | when: ansible_os_family == "Debian" 15 | 16 | - name: Define git_install_from_source_dependencies. 17 | set_fact: 18 | git_install_from_source_dependencies: "{{ __git_install_from_source_dependencies | list }}" 19 | when: git_install_from_source_dependencies is not defined 20 | 21 | - name: Ensure git's dependencies are installed. 22 | package: 23 | name: "{{ git_install_from_source_dependencies }}" 24 | state: present 25 | 26 | - name: Get installed version. 27 | command: git --version 28 | changed_when: false 29 | failed_when: false 30 | check_mode: false 31 | register: git_installed_version 32 | 33 | - name: Force git install if the version numbers do not match. 34 | set_fact: 35 | git_reinstall_from_source: true 36 | when: 37 | - git_install_from_source_force_update | bool 38 | - (git_installed_version.rc == 0) and (git_installed_version.stdout | regex_replace("^.*?([0-9\.]+)$", "\\1") is version(git_version, operator="!=")) 39 | 40 | - name: Download git. 41 | get_url: 42 | url: "https://www.kernel.org/pub/software/scm/git/git-{{ git_version }}.tar.gz" 43 | dest: "{{ workspace }}/git-{{ git_version }}.tar.gz" 44 | when: (git_installed_version.rc != 0) or (git_reinstall_from_source | bool) 45 | 46 | - name: Expand git archive. 47 | unarchive: 48 | src: "{{ workspace }}/git-{{ git_version }}.tar.gz" 49 | dest: "{{ workspace }}" 50 | creates: "{{ workspace }}/git-{{ git_version }}/README" 51 | copy: false 52 | mode: 0755 53 | when: (git_installed_version.rc != 0) or (git_reinstall_from_source | bool) 54 | 55 | - name: Build git. 56 | command: > 57 | make prefix={{ git_install_path }} {{ item }} 58 | chdir={{ workspace }}/git-{{ git_version }} 59 | with_items: 60 | - all 61 | - install 62 | when: (git_installed_version.rc != 0) or (git_reinstall_from_source | bool) 63 | become: true 64 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ensure git is installed (RedHat). 3 | package: 4 | name: "{{ git_packages }}" 5 | state: present 6 | enablerepo: "{{ git_enablerepo | default(omit, true) }}" 7 | when: 8 | - not git_install_from_source | bool 9 | - ansible_os_family == 'RedHat' 10 | 11 | - name: Update apt cache (Debian). 12 | apt: update_cache=true cache_valid_time=86400 13 | when: ansible_os_family == 'Debian' 14 | 15 | - name: Ensure git is installed (Debian). 16 | apt: 17 | name: "{{ git_packages }}" 18 | state: present 19 | when: 20 | - not git_install_from_source | bool 21 | - ansible_os_family == 'Debian' 22 | 23 | - import_tasks: install-from-source.yml 24 | when: git_install_from_source | bool 25 | -------------------------------------------------------------------------------- /vars/Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | git_install_from_source_dependencies: 3 | - libcurl4-gnutls-dev 4 | - libexpat1-dev 5 | - gettext 6 | - libssl-dev 7 | - zlib1g-dev 8 | - build-essential 9 | - gcc 10 | -------------------------------------------------------------------------------- /vars/Fedora.yml: -------------------------------------------------------------------------------- 1 | --- 2 | git_install_from_source_dependencies: 3 | - gettext-devel 4 | - expat-devel 5 | - curl-devel 6 | - zlib-devel 7 | - perl-devel 8 | - openssl-devel 9 | - subversion-perl 10 | - make 11 | - gcc 12 | - tar 13 | -------------------------------------------------------------------------------- /vars/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | git_install_from_source_dependencies: 3 | - gettext-devel 4 | - expat-devel 5 | - curl-devel 6 | - zlib-devel 7 | - perl-devel 8 | - openssl-devel 9 | - subversion-perl 10 | - make 11 | - gcc 12 | -------------------------------------------------------------------------------- /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This space intentionally left blank. 3 | --------------------------------------------------------------------------------