Free cookie consent management tool by TermsFeed Policy Generator

/dev/blog/ID10T

Ansible: Using Python string substituition in variables

Ansible, Codebites Comments

Advertisement

Scenario: Utilize Pythons string substitution in Ansible variables

- hosts: localhost
  connection: local

  vars:
    foobar: ">>%s<<"
    substitution: "adminswerk.de"

  tasks:
    - debug:
        msg: "{{ foobar % substitution }}"

Output (slightly truncated):

$ ansible-playbook string_format.yml
PLAY [localhost] **********************************************************************************************************************************************

TASK [debug] **************************************************************************************************************************************************
ok: [localhost] => {
    "msg": ">>adminswerk.de<<"
}

PLAY RECAP ****************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0

Advertisement

comments powered by isso

Advertisement