14

I am writing a rolling upgrade playbook and would like to print out the hostname of current host been upgraded.

I put inventory_hostname and ansible_hostname in task names but that did not work

- name: upgrade softare on {{inventory_hostname}}
- name: current host is {{ansible_hostname}}

debug works fine

- name: Test a variable
  debug: var=inventory_hostname

TASK: [Test a variable] ******************************************************* 
ok: [SERV14] => {
    "var": {
        "inventory_hostname": "SERV14"
    }
}

So what should I do to be able to use those variables in task name descriptions.

Thanks

  • 3
    Currently, variable substitution can not be done in name. See here – cuonglm May 8 '15 at 7:39
20

Starting from v2.0 Ansible supports variable substitution in task/handler names: https://github.com/ansible/ansible/issues/10347, so these examples will work as expected:

- name: upgrade software on {{inventory_hostname}}
- name: current host is {{ansible_hostname}}
0

I think bro you should write the {{ ansible_hostname }} after the tasks: , because before that it doesn't gathered facts so it didn't give the result .(I may be wrong in the concept but practical was successful)

tasks:

  • name: Install the httpd on {{ ansible_hostname }} (here . means -)

    yum:

    name: httpd 
    
    state: latest
    

    enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.