You just don’t know how to do it.
You’ve been thinking about it for a while too. It’s an important issue. The crafting of the spell is the most important part. The journey is usually more important than the destination itself. But you don’t feel like you are doing it right.
The purpose is simple, yet it has a duality of character. You want to enable the transmission of information between all realms into a single library of knowledge. A task you’ve already accomplished many times in the past.
---
# filebeat/tasks/main.yml
- name: install Filebeat
package:
name: filebeat={{ elk_version }}
state: present
update_cache: true
notify: restart Filebeat
- name: copy configuration file
template:
src: filebeat.yml.j2
dest: /etc/filebeat/filebeat.yml
owner: root
group: root
mode: 0600
notify: restart Filebeat
- name: start Filebeat
service:
name: filebeat
state: started
enabled: true
You have crafted this spell properly, following the same principles you have taught many people across the years, the same ones you’ve used for your own. The same ones that Merlin taught you the first time he showed you how to create a playground to refine your creations, thousand of years ago.
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_filebeat_is_installed(host):
filebeat = host.package('filebeat')
assert filebeat.is_installed
def test_filebeat_is_running(host):
filebeat = host.service('filebeat')
assert filebeat.is_running
def test_filebeat_is_enabled(host):
filebeat = host.service('filebeat')
assert filebeat.is_enabled
def test_filebeat_configuration_exists(host):
filebeat = host.file('/etc/filebeat/filebeat.yml')
assert filebeat.exists
Nevertheless, you want to add an extension to the spell, depending on whether you want to receive information about all the portals you’ve spawned into this world or not. Visualisation is key.
---
# filebeat/tasks/main.yml
...
- name: include module tasks
import_tasks: nginx_module.yml
when: activate_filebeat_nginx_module
---
# filebeat/tasks/nginx_module.yml
- name: copy nginx module file
template:
src: nginx.yml.j2
dest: /etc/filebeat/modules.d/nginx.yml
owner: root
group: root
mode: 0644
register: nginx_module
notify: restart Filebeat
- name: setup filebeat
shell: filebeat setup -e && touch /tmp/filebeat_configured
when: nginx_module.changed
tags:
- skip_ansible_lint
You know how to craft the general part of the spell, but not the extension. If only…
N appears out of thin air.
He’s good.
You’re confused.
N pulls up his sleeves and steps forward.
N waves his hands around in the air. Light appears everywhere, and you can see the structure of your current spell:
filebeat/
├── README.md
├── defaults
│ └── main.yml
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── molecule
│ └── default
└── tasks
├── main.yml
└── nginx_module.yml
N waves his hands once again in the air and the light and the images change:
---
# filebeat/molecule/default/playbook.yml
- name: Converge
hosts: all
roles:
- role: filebeat
You have seen this before, but you’ve never really understood the abstractions or their meaning, even if you’ve already been doing this for a while. You feel on the verge of enlightenment.
N claps his hands, and energy starts flowing through him as a new component of the enclosure you used in order to craft your test appears.
`molecule init scenario --scenario-name activate_filebeat_nginx_module --role-name filebeat`
--> Initializing new scenario activate_filebeat_nginx_module...
Initialized scenario in filebeat/molecule/activate_filebeat_nginx_module successfully.
molecule
├── activate_filebeat_nginx_module
│ ├── Dockerfile.j2
│ ├── INSTALL.rst
│ ├── create.yml
│ ├── destroy.yml
│ ├── molecule.yml
│ ├── playbook.yml
│ ├── prepare.yml
│ └── tests
└── default
├── Dockerfile.j2
├── INSTALL.rst
├── create.yml
├── destroy.yml
├── molecule.yml
├── playbook.yml
├── prepare.yml
└── tests
You both walk to the new part of the playground.
You mold the spell accordingly.
---
# filebeat/molecule/activate_filebeat_nginx_module/playbook.yml
- name: Converge
hosts: all
roles:
- role: filebeat
activate_filebeat_nginx_module: true
You are impressed with N. It’s hard to believe that you were the one teaching him things once. Maybe he’s been the one teaching you all from the start.
You’re having a déjà-vu. N is outside your field of vision. You slowly turn your head around...
N is still there.