44

I am working on a playbook to join linux systems to Active Directory. I can't seem to find a way to convert the value of ansible_hostname to uppercase. One of the commands I need to run requires the hostname to be supplied in uppercase.

grahamjgreen
  • 841
  • 2
  • 8
  • 12

2 Answers2

85

As Hector Valverde mentionned, it seems to be

{{ ansible_hostname|upper }}

...rather than "uppercase"

Pom12
  • 966
  • 8
  • 5
  • 29
    Similarly, there's also `{{ ansible_hostname | lower }}` instead of [Jinja2's documented `lower()`](http://jinja.pocoo.org/docs/dev/templates/#lower) – bmaupin Oct 06 '16 at 15:56
6

In my case to convert the value of a variable to uppercase pipe the variable to upper like so:

{{ ansible_hostname|upper }}
grahamjgreen
  • 841
  • 2
  • 8
  • 12
  • 3
    How did you find this? Did you read some documentation? – 030 Mar 23 '15 at 20:21
  • 10
    It should be documented on http://docs.ansible.com/playbooks_filters.html but like many things in Ansible it's assumed you "just know"; I'm often frustrated by this as well. E.g. there are multiple examples of how to define a host variable (ntp server is used as an example) but how to actually *use* such a host variable is not explained anywhere. – wurtel Mar 24 '15 at 10:13
  • 3
    Actually is: {{ ansible_hostname|upper }} –  Apr 29 '15 at 15:43
  • 2
    @wurtel See http://jinja.pocoo.org/docs/templates/#builtin-filters for all the filters that aren't documented directly at Ansible. – Tim Malone Jun 22 '18 at 22:56