Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string to list slice in ansible

Ansible 2.2

I want to get to the slices of the below variable, how would I do so ?

hostvars[inventory_hostname]['ansible_hostname']|list

basically I have a hostname, hostname001 that I wish to retrieve the last two characters on.

How do I split it and slice it?

like image 275
Simply Seth Avatar asked Mar 11 '23 04:03

Simply Seth


1 Answers

Try ansible_hostname[-3:].

Why do you use hostvars[inventory_hostname]['ansible_hostname'] instead of simply ansible_hostname?

For strings and lists you may use Python slicing technics.

like image 193
Konstantin Suvorov Avatar answered May 16 '23 07:05

Konstantin Suvorov