#
ドキュメント

Document

自分のための備忘録です。

Ansible

https://docs.ansible.com/ansible/2.9_ja/index.html

hosts

The hosts line is a list of one or more groups or host patterns, separated by colons, as described in the Patterns: targeting hosts and groups documentation. The remote_user is just the name of the user account:

https://docs.ansible.com/ansible/2.9/user_guide/playbooks_intro.html

- hosts: webservers
  remote_user: root

Tasks list

Each play contains a list of tasks. Tasks are executed in order, one at a time, against all machines matched by the host pattern, before moving on to the next task.

https://docs.ansible.com/ansible/2.9/user_guide/playbooks_intro.html#tasks-list

- hosts: all
  # ...
  tasks:
    - users
    - name: shell command
      shell: /usr/bin/somecommand || /bin/true

tasksは、rolesで指定することができる。 rolesを使用する場合の例。

- hosts: all
  # ...
  roles:
    - users

rolesで指定された場合、Ansibleはは/path/to/project/roles/{{task name}}/tasks/main.ymlを実行する。
↑の例では/path/to/project/roles/users/tasks/main.ymlを実行する。

Working With Modules

Ansible ships with a number of modules (called the ‘module library’) that can be executed directly on remote hosts or through Playbooks.

Creating Reusable Playbooks

Roles

Roles are ways of automatically loading certain vars_files, tasks, and handlers based on a known file structure. Grouping content by roles also allows easy sharing of roles with other users.

https://docs.ansible.com/ansible/2.9/user_guide/playbooks_reuse_roles.html

group_vars

[my_group_bastion] <-- グループ名がmy_group_bastion
my_group_bastion ansible_python_interpreter=/usr/bin/python2

[my_group_db]
my_group_db ansible_python_interpreter=/usr/bin/python2

グループ名ごとに/path/to/project/group_vars/{{group name}}にファイルを格納

例)

  • /path/to/project/group_vars/my_group_bastionにユーザーを記載したvars.ymlを配置
  • /path/to/project/group_vars/my_group_dbvars.ymlvault.ymlを配置