[PYTHON] Try installing Git from source using Ansible's make and unarchive modules

■ Introduction

■ PlayBook to install Git from source

playbook.yml


---
- hosts: all
  remote_user: ec2-user
  become: true
  vars:
    version: 2.9.0
    prefix_dir: /usr/local
    src_dir: "{{ prefix_dir }}/src"
    bin_dir: "{{ prefix_dir }}/bin"
  tasks:
    - name: original git exist check
      stat: path={{ bin_dir }}/git
      register: exist_git

    - debug: msg="git not installed."
      when: exist_git.stat.exists == false

    - name: original git version check
      command: "{{ bin_dir }}/git --version warn=false"
      register: org_version
      changed_when: false
      when: exist_git.stat.exists == true

    - name: install dependences
      yum: name={{ item }}
      with_items:
        - curl-devel
        - expat-devel
        - gettext-devel
        - openssl-devel
        - zlib-devel
        - gcc
        - perl-ExtUtils-MakeMaker
      when: (exist_git.stat.exists == false) or
            (exist_git.stat.exists == true and org_version.stdout != "git version {{ version }}")

    - name: make download dir
      file: path={{ src_dir }} state=directory owner=root group=root mode=755
      when: (exist_git.stat.exists == false) or
            (exist_git.stat.exists == true and org_version.stdout != "git version {{ version }}")

    - name: download git version {{ version }}
      unarchive:
        src: https://www.kernel.org/pub/software/scm/git/git-{{ version }}.tar.gz
        dest: "{{ src_dir }}"
        copy: no
      when: (exist_git.stat.exists == false) or
            (exist_git.stat.exists == true and org_version.stdout != "git version {{ version }}")

    - name: make all
      make:
        chdir: "{{ src_dir }}/git-{{ version }}"
        target: all
        params:
          prefix: "{{ prefix_dir }}"
      when: (exist_git.stat.exists == false) or
            (exist_git.stat.exists == true and org_version.stdout != "git version {{ version }}")

    - name: make install
      make:
        chdir: "{{ src_dir }}/git-{{ version }}"
        target: install
        params:
          prefix: "{{ prefix_dir }}"
      when: (exist_git.stat.exists == false) or
            (exist_git.stat.exists == true and org_version.stdout != "git version {{ version }}")

The execution is as follows.

$ ansible-playbook playbook.yml

Remarks

■ About make module and changed

Ansible's make module will be chenged every time I run it as it is. I want it to be changed when I first run the PlayBook, but I want it to be ʻok instead of changedwhen I rerun the same PlayBook. However, if you specifychanged_when: False, it will be ʻok even though the change was made at the first execution, so you should avoid specifying changed_when: False. So, this time, I added a version check function that combines register and when.

■ About the combination of unarchive module and https

The combination of ʻun archive and https was the songwriter. It worked fine on Amazon Linux, but it didn't work when I set the proxy in an environment where the proxy authenticates. Probably because you didn't specify to invalidate the SSL certificate. The ʻunarchive module has a validate_certs option, and it is OK if you specify validate_crets = no, but this option is not supported unless it is Ansible ver.2.2 or later. In the environment before Ansible ver.2.1, it was necessary to download with the combination of get_url, https and validate_crets = no.

■ Conclusion

This time, I tried installing Git from the source, but if you install a package that is not published by rpm from the source, it seems that this PlayBook can be applied.

Well then.

Recommended Posts

Try installing Git from source using Ansible's make and unarchive modules
Compile and install Git from source.
Try to make it using GUI and PyQt in Python
Try using pytest-Overview and Samples-
Try using Amazon DynamoDB from Python
Introduce git from source into Linux environment using wget with non-root privileges