advanced varibles and string operations

Why is it that this variable assignment works:

is_cent5: “‘$ansible_distribution’ == ‘CentOS’ and ‘$ansible_distribution_version’.startswith(‘5’)”

But this one does not:

inventory_host: “‘$inventory_hostname’.split(‘.’)[0]”

What’s the difference?

I’ve tried every different incantation of the second line I can think of but the output always ends up with the ‘split(’.‘)[0]’ crap in it instead of being referenced properly.