-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Ansible is an automation tool used for configuration management using human-readable YAML templates. Ansible is distinguished for being agentless, meaning no special software is required on the nodes it manages.
Ansible playbooks represent a sequence of scripted actions which apply changes uniformly over a set of hosts. Modules are standalone scripts that enable a particular task across many OSes, services, applications, etc. Predefined modules are available in the module library, and new ones can be defined via Python or JSON.
Ansible host management relies on a .ini
file containing a list of IP addresses or hostnames organized in groups.
There are several areas where Ansible can be used in personal projects for learning purposes. ref
- Use the
users
module to manage users, assign groups, and define custom aliases in theprofile
property. - Put a time limit on the availability of the
sudo
command - Use Ansible Tower to produce a GUI interface to restart certain services.
- Use Ansible Tower to look for files larger than a particular size in a directory.
- Debug a system performance problem.
Ansible can be used in one of two ways:
- Running ad hoc commands, that is commands executed in realtime by an administrator working at the terminal, using the
ansible
command. - Running playbooks, YAML documents containing tasks each of which are equivalent to a single ad hoc command, using the
ansible-playbook
command. Any ad hoc command can be rewritten as a playbook, but some modules can only be used effectively as playbooks.
Playbooks, in turn, can be written in two styles:
- Using "
k=v
" syntax, where keys and values are defined inline
tasks:
- name: Install htop
dnf: name=htop state=latest
- Using proper YAML syntax
tasks:
- name: Install htop
dnf:
name: htop
state: latest
Variable substitution is done by specifying the name of the placeholder variable and its value under vars
as a sibling to tasks
and handlers
linuxjournal.com
---
- hosts: webservers
become: yes
vars:
package_name: apache2
tasks:
- name: this installs a package
apt: "name={{ package_name }} update_cache=yes state=latest"
notify: enable apache
handlers:
- name: enable apache
service: "name={{ package_name }} enabled=yes state=started"
Conditional logic is implemented with each task by defining a condition as the value for a property when
linuxjournal.com
---
- hosts: webservers
become: yes
tasks:
- name: install apache this way
apt: name=apache2 update_cache=yes state=latest
notify: start apache2
when: ansible_os_family == "Debian"
- name: install apache that way
yum: name=httpd state=latest
notify: start httpd
when: ansible_os_family == "RedHat"
handlers:
- name: start apache2
service: name=apache2 enabled=yes state=started
- name: start httpd
service: name=httpd enabled=yes state=started
ansible
ansible-doc
ansible-galaxy
ansible-inventory
ansible-playbook
- apt ?
- archive ?
- cli_config ?
- command ?
- copy ?
- debug ?
- dnf ?
- file ?
- git ?
- lineinfile ?
- package ?
- ping ?
- raw ?
- service ?
- setup ?
- shell ?
- template?
- Ad hoc command
- Ansible Galaxy
- Ansible Tower
- Ansible Vault
- AWX
- Configuration files
- EPEL
- Fact
- Handler
- Inventory
- Module
- Module Library
- Play
- Playbook
- Role
- Task
- Vault