Ubuntu 18.04 LTS
# apt update # apt install ansible
~/Ansible に inventory ファイル,Playbook ファイル,var ファイルのサンプルを作った. $ mkdir ~/Ansible $ cd ~/Ansible $ cp /etc/ansible/ansible.cfg . $ cp /etc/ansible/hosts inventory
~/Ansible/ ├── ansible.cfg ├── group_vars │ ├── all.yml │ ├── nfs.yml │ ├── db.yml │ └── web.yml ├── inventory ├── pb_nfs_cmd.yml ├── pb_db_cmd.yml └── pb_web_cmd.yml
% ansible-playbook -i inventory pb_web_cmd.yml
[defaults] host_key_checking = False
ansible_ssh_private_key_file: ~/.ssh/id_rsa ansible_python_interpreter: /usr/bin/python3
[localhost] 127.0.0.1 ansible_connection=local [nfs] nfs [db] db01 [web] web01 web02
- hosts: web gather_facts: no vars: sample_vars: TEST Message tasks: - shell: uptime register: result - debug: msg: "{{ result.stdout }}" - debug: msg: "{{ sample_vars }}"