LoginSignup
32
29

More than 5 years have passed since last update.

ansibleのBest Practiceなディレクトリをshellで作る

Last updated at Posted at 2014-02-19

課題

anslibleの公式サイトでBest Practiceな構成が公開されているが、1回作ればそんなに変えるもんじゃないから頑張ってディレクトリ作りそう。。だけど、しばらくは変わらないだろうということでベースのディレクトリをただただ作るshellを作成してみた。

仕様

  • BestPracticeをコピペなのでディレクトリ名はほぼ使用できると思いますが、ファイル名は適宜修正してください。
  • web/dbはおおよそ必要なのではないかと用意したが適宜追加してください

作成されるディレクトリ構成

anslibleの公式サイトのままですが、念のため

.
├── stage
├── production
├── group_vars
│   └── group1
├── host_vars
│   └── hostname1
├── roles
│   ├── common
│   │   ├── files
│   │   ├── handlers
│   │   │   └── main.yml
│   │   ├── tasks
│   │   │   └── main.yml
│   │   ├── templates
│   │   │   └── templates.j2
│   │   └── vars
│   │       └── main.yml
│   ├── dbtier
│   │   ├── files
│   │   ├── handlers
│   │   │   └── main.yml
│   │   ├── tasks
│   │   │   └── main.yml
│   │   ├── templates
│   │   │   └── templates.j2
│   │   └── vars
│   │       └── main.yml
│   └── webtier
│       ├── files
│       ├── handlers
│       │   └── main.yml
│       ├── tasks
│       │   └── main.yml
│       ├── templates
│       │   └── templates.j2
│       └── vars
│           └── main.yml
├── site.yml
├── dbservers.yml
└── webservers.yml

スクリプト

create_ansible_file.sh
#!/bin/bash

# Create ansible Best Practice directory
# http://docs.ansible.com/playbooks_best_practices.html#directory-layout
# 2014/02/19
# version 0.1

CREATE_ROLES_DIR="common webtier dbtier"

echo "# inventory file for production servers" > production
echo "# inventory file for stage environment" > stage
mkdir group_vars
echo "# here we assign variables to particular groups" > group_vars/group1
mkdir host_vars
echo "# if systems need specific variables, put them here" > host_vars/hostname1
echo "# master playbook" > site.yml
echo "# playbook for webserver tier" > webservers.yml
echo "# playbook for dbserver tier" > dbservers.yml

# this hierarchy represents a "role"
for ROLES_DIR in ${CREATE_ROLES_DIR}
do
  mkdir -p roles/${ROLES_DIR}/{tasks,handlers,templates,files,vars}
  echo "# tasks file can include smaller files if warranted" > roles/${ROLES_DIR}/tasks/main.yml
  echo "# handlers file" > roles/${ROLES_DIR}/handlers/main.yml
  echo "# templates end in .j2" > roles/${ROLES_DIR}/templates/templates.j2
  echo "# variables associated with this role" > roles/${ROLES_DIR}/vars/main.yml
done

exit

まとめ

もう少しやりようがあった気がするが。。。ちょっとした手間は省けるかもしれないです。徐々に直していきます。

32
29
2

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
32
29