March 2019
Intermediate to advanced
412 pages
9h 49m
English
Let's say we have a requirement to work with just the filename from a full path. Obviously, we could perform some complex pattern matching to do this, but often this results in code that is not easy to read, and can be difficult to maintain. Luckily, Ansible provides a filter specifically for extracting the filename from a full path, as we shall demonstrate. In this example, we will use the basename filter to extract the filename from a full path:
---- name: demo the filters hosts: localhost gather_facts: false tasks: - name: demo basename debug: msg: "{{ '/var/log/nova/nova-api.log' | basename }}"
The output is shown in the following screenshot:
Here, we can see that just the filename was returned from the full path, as desired. ...
Read now
Unlock full access