Ansible Cheatsheet
Ansible can be both declarative and procedural—many modules work declaratively, while other modules prefer a procedural programming approach. Additionally, some constructs in the Ansible language, such as conditionals and loops, allow the users to define a procedural logic.
Built-in
Copy files
ansible.builtin.copy
: from local to remote.ansible.builtin.fetch
: from remote to local.ansible.builtin.slurp
: fetching a base64-encoded blob containing the data in a remote file.
Execute
ansible.builtin.command
: execute command on selected nodes.ansible.builtin.shell
: almost exactly like the ansible.builtin.command module but runs the command through a shell (/bin/sh) on the remote node.ansible.builtin.script
: The local script at path will be transferred to the remote node and then executed. does not require python on the remote system
Ansible
The key difference / advantage is agent-less.
- Target machines / nodes are termed as "inventory"
- only depend on OpenSSH and Python
- Playbooks use an easy and descriptive language based on YAML and Jinja templates.
It also has a strong focus on security and reliability, featuring a minimum of moving parts, usage of OpenSSH for transport (with other transports and pull modes as alternatives), and a language that is designed around auditability by humans–even those not familiar with the program.
Ansible is an IT automation tool. It can configure systems, deploy software, and orchestrate more advanced IT tasks such as continuous deployments or zero downtime rolling updates.
Ansible can be used to manage bare metal machines: configuring the machines, installing packages, and Kubernetes components.
ansible-playbooks
: yaml files.
Key features
- Agentless: SSH protocol is used to connect to servers and work on them instead of external agents; (Chef and Puppet follow master-agent or master-slave architecture.)
- Idempotent: same operations provide the same result as many times as they are carried out;
- Easy and expandable: Ansible is written in Python and uses YAML to write the commands. (Chef and Puppet use Ruby DSL.)
Ansible vs Ansible Tower vs ansible-runner
- Ansible: open source
- Ansible Tower: enterprise version
- ansible-runner: a wrapper around Ansible execution. Ways to use it:
- A stand alone
ansible-runner
CLI command. - A reference container image for k8s.
- A python module.
- A stand alone