Ansible: variable interpolation in task name

前端 未结 3 1772
心在旅途
心在旅途 2021-02-07 01:59

I cannot get this seemingly simple example to work in Ansible 1.8.3. The variable interpolation does not kick in the task name. All examples I have seen seem to suggest this sho

3条回答
  •  面向向阳花
    2021-02-07 03:01

    I experienced the same problem today in one of my Ansible roles and I noticed something interesting.
    When I use the set_fact module before I use the vars in the task name, they actually get translated to their correct values.

    In this example I wanted to set the password for a remote user:
    Notice that I use the vars test_user and user_password that I set as facts before.

    - name: Prepare to set user password
      set_fact:
        user_password: "{{ linux_pass }}"
        user_salt: "s0m3s4lt"
        test_user: "{{ ansible_user }}"
    
    - name: "Changing password for user {{ test_user }} to {{ user_password }}"
      user:
       name: "{{ ansible_user }}"
       password: "{{ user_password | password_hash('sha512', user_salt) }}"
       state: present
       shell: /bin/bash
       update_password: always
    

    This gives me the following output:

    TASK [install : Changing password for user linux to LiNuXuSeRPaSs#]
    

    So this solved my problem.

提交回复
热议问题