https://docs.ansible.com/ansible/2.9_ja/index.html
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
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
を実行する。
Ansible ships with a number of modules (called the ‘module library’) that can be executed directly on remote hosts or through Playbooks.
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
[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_db
にvars.yml
とvault.yml
を配置