今日からAnsible始めました!
YAMLにちょこちょこっと書くだけの簡単な作業でそれなりのことができたので、本当に学習コストが小さくて、あっという間にAnsible LOVEになってしまいそうです。
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を使うのがかったるかったり、という場合の助けになるとのことです。
使ってみた
開発サーバー用のいつもの設定を書いてみました。
- 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"
おかげさまでシェルスクリプト地獄から開放されました