要在ansible中列出切片的字符串
表2.2 我想获得下面变量的切片,我将如何做到这一点要在ansible中列出切片的字符串,ansible,ansible-2.x,Ansible,Ansible 2.x,表2.2 我想获得下面变量的切片,我将如何做到这一点 hostvars[inventory_hostname]['ansible_hostname']|列表 基本上,我有一个主机名,hostname001,我希望从中检索最后两个字符 如何将其拆分和切片?试试ansible\u主机名[-3:] 为什么使用hostvars[inventory\u hostname]['ansible\u hostname']而不是简单的ansible\u hostname 对于字符串和列表,可以使用Python切片
hostvars[inventory_hostname]['ansible_hostname']|列表
基本上,我有一个主机名,hostname001
,我希望从中检索最后两个字符
如何将其拆分和切片?试试
ansible\u主机名[-3:]
为什么使用hostvars[inventory\u hostname]['ansible\u hostname']
而不是简单的ansible\u hostname
对于字符串和列表,可以使用Python切片技术