Ansible is used to perform tasks on one or more target system. For example, one possible task could be to install software on a system. The system that Ansible is installed on is known as the Control Node, and the target systems are known as the Managed Node or host.
Command Line Tools (CLI)
Typically, tasks are performed using the `ansible` command or the `ansible-playbook` command.
The ansible command is used to perform an ad-hoc task, which is a single task. For example, the ansible command can be used to ping all managed nodes.
ansible all -m ping
The ansible-playbook command is used for orchestration, which is just a fancy way of saying to perform one or more tasks. For example, the ansible-playbook command could be used to set up an HTTPD web server, where the series of tasks could be to install the HTTPD software, configure the web server, and then start and enable the web server.
At a very high level, Ansible commands takes two pieces of input:
- The managed nodes to run tasks against, commonly refered to as inventory or the hosts files
- The tasks to run on the managed nodes
The ansible-playbook command is used to perform the tasks in a playbook. A playbook is a YAML file, such as foo.yml or bar.yaml. The YAML file will contain a series of tasks. For example, the httpd.yml playbook would probably consists of tasks to download the HTTPD installation files, to install HTTPD, and to then start and enable the HTTPD web server. Refer to Getting Started with Playbook to better understand playbooks.
Defining Managed Nodes (hosts / inventory)
Managed nodes are defined in inventory. There are various ways to define your inventory:
- Create a static inventory file on your Ansible control node
- Create a dynamic inventory file on your Ansible control node
- Create a static inventory in Ansible Tower
- Create a smart inventory in Ansible Tower
Ansible uses Python to perform tasks and expects the Python command line tool to be located at /usr/bin/python. The ansible --version command can be used to determine the version of Python the control node is using.
- If a managed node does not have Python installed, the raw module can be used to install Python on the system.
- If a managed node has both version 2.x.x (/usr/bin/python) and version 3.x.x (/usr/bin/python3), the ansible_python_interpreter variable can be used to tell Ansible to use /usr/bin/python.
By default, Ansible uses SSH to connect to the managed node(s). This can be changed to some other protocol. However, assuming you'll be using SSH, you must be able to make an SSH connection from the control node to the managed node(s). Refer to our article on Getting Started with SSH to understand how to configure Ansible and your managed nodes for SSH.