LoginSignup
13
13

More than 5 years have passed since last update.

Ansible 2.1からはサクッとgit configができる

Posted at

今日からAnsible始めました!

YAMLにちょこちょこっと書くだけの簡単な作業でそれなりのことができたので、本当に学習コストが小さくて、あっという間にAnsible LOVE:two_hearts:になってしまいそうです。

git_config module

表題の件ですが、Ansible 2.1からはgit_config moduleを利用してgit configができるんですね。

git_config - Read and write git configuration — Ansible Documentation

The git_config module changes git configuration by invoking ‘git config’. This is needed if you don’t want to use template for the entire git config file (e.g. because you need to change just user.email in /etc/.git/config). Solutions involving command are cumbersone or don’t work correctly in check mode.

ちょっと設定を変えるだけのためにファイル丸ごと分のtemplateを使うのがイヤだったり、check modeでうまくいかないcommandを使うのがかったるかったり、という場合の助けになるとのことです。

使ってみた

開発サーバー用のいつもの設定を書いてみました。

roles/git/tasks/main.yml
- name: ensure git is at the latest version
  become: yes
  yum: name=git state=latest
- git_config: name=user.name scope=global value="{{ name }}"
- git_config: name=user.email scope=global value="{{ email }}"
- git_config: name=color.ui scope=global value=true
- git_config: name=grep.lineNumber scope=global value=true
- git_config: name=alias.find scope=global value="grep -H --heading --break"
- git_config: name=core.editor scope=global value="vi -u NONE -N"

おかげさまでシェルスクリプト地獄から開放されました :thumbsup:

13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13