Ansible 2.2: register with a variable in the name

79 views
Skip to first unread message

Andreas Olsson

unread,
Nov 27, 2016, 4:23:58 AM11/27/16
to Ansible Project
Greetings

Since moving from Ansible 2.1.3 to Ansible 2.2.0 I have run into an
issue with register, and when it's variable name is built up using a
variable. I have no idea if this is due to a regression in Ansible 2.2,
or if I have been doing something wrong/unsupported which I finally got
bitten by.

Anyway, this being what breaks between 2.1.3 and 2.2.0. Context wise
it's part of a parameterize role.

- name:  Add {{ repo_name }} sources
  template:
     src={{ repo_name }}.list.j2
     dest=/etc/apt/sources.list.d/{{ repo_name }}.list
     owner=root
     group=root
     mode=0444
  register: reg_{{ repo_name }}_sources

- name: debug reg_{{ repo_name }}_sources
  debug: var=reg_{{ repo_name }}_sources

Running Ansible 2.1.3 I get the following expected output.

TASK [repo : Add gitppa sources] ***********************************************
ok: [vagmast]

TASK [repo : debug reg_gitppa_sources] *****************************************
ok: [vagmast] => {
     "reg_gitppa_sources": {
         "changed": false, 
         "diff": {
             "after": {
                 "path": "/etc/apt/sources.list.d/gitppa.list"
             }, 
             "before": {
                 "path": "/etc/apt/sources.list.d/gitppa.list"
             }
         }, 
        "gid": 0, 
         "group": "root", 
         "mode": "0444", 
         "owner": "root", 
         "path": "/etc/apt/sources.list.d/gitppa.list", 
         "size": 61, 
         "state": "file", 
         "uid": 0
     }
}

While with Ansible 2.2 that register never appear to happen.

TASK [repo : Add gitppa sources] ***********************************************
ok: [vagmast]

TASK [repo : debug reg_gitppa_sources] *****************************************
ok: [vagmast] => {
    "reg_gitppa_sources": "VARIABLE IS NOT DEFINED!"
}

Any idea what I'm doing wrong, or what I should try?

// Andreas

Andreas Olsson

unread,
Dec 2, 2016, 11:52:28 PM12/2/16
to ansible...@googlegroups.com
Ok, here is a minimal playbook showing my particular issue.

  ---
  - hosts: localhost
    vars:
      foo: pwfile
    tasks:
      - name: lookup /etc/passwd
        stat: path=/etc/passwd
        register: abc_{{ foo }}_def
      - name: Display abc_{{ foo }}_def content
        debug: var=abc_{{ foo }}_def

If I run this playbook using Ansible 2.1.3 it will display the full
stat result for /etc/passwd. If I instead use Ansible 2.2.0 I get the
following output from the debug task.

TASK [Display abc_pwfile_def content] ******************************************
ok: [localhost] => {
     "abc_pwfile_def": "VARIABLE IS NOT DEFINED!"
}

So, is this a bug/regression in Ansible 2.2, or were I relying on an
unsupported behavior?

// Andreas
Reply all
Reply to author
Forward
0 new messages