When I was working at IBM, I applied a dedicated cluster for Ansible learning. After I left, I decide to use Vagrant to create local cluster for the same purpose.
NOTE: I have also created a docker sponsored Ansible testing environment, please see here
Please check Vagrant Ansible testing cluster repo. Follow the README to set up and play with ansible. The problems I had at the time of creating the repo:
- how to establish the SSH connection to Vagrant VM.
- the
sed
insert has subtle difference in Mac.
Ansible Install
- Control node requirements:
Starting with
ansible-core 2.11
, the project will only be packaged for Python3.8
and newer.
If you are using Ansible to manage machines in a cloud, consider using a machine inside that cloud as your control node. In most cases Ansible will perform better from a machine on the cloud than from a machine on the open Internet.
Managed node requirements: Although you do not need a daemon on your managed nodes, you do need a way for Ansible to communicate with them. For most managed nodes, Ansible makes a connection over SSH and transfers modules using SFTP. For any machine or device that can run Python, you also need Python 2 (version 2.6 or later) or Python 3 (version 3.5 or later).
If install on Linux using yum (I use pip install in virtualenv in the demo, see repo README):
1 | # search ansible package |
Ansible Inventory
How to build your inventory, for inventory
file, 主要涉及一些ssh connection的设置.
Position the target hosts from group
Ansible Config
Ansible Configuration Settings
for ansible.cfg
file.
- ansible callback plugin: use
stdout_callback = debug
is fine in most cases.
Ansible Yaml Format
Yaml syntax,
Especially the difference between >
and |
for multi-line coding:
Spanning multiple lines using a |
will include the newlines and any trailing
spaces. Using a >
will fold newlines to spaces; In either case the indentation
will be ignored.
1 | include_newlines: | |
Ansible Run
Ad-hoc command example:
1 | # -v: verbose, display output |
Playbook Role, check role directory structure and how to use role.
1 | # -e|--extra-vars: pass extra variables |