2

I am using Ansible 2.3.0.0 and I have tested in Ansible 2.4.0.0, obtaining the same result. My problem is very simple, but I cannot see the problem.

I have defined a list of objects in Ansible as follows:

  vars:
     password_text_to_encrypt:
          - { line: "{{truststore_pass }}" , regexp: '\${TRUSTSTORE_PASS}*'}
          - { line: "{{ keystore_pass }}" , regexp: '\${KEYSTORE_PASS}*'}
          - { line: "{{ gp_pass }}" , regexp: '\${GP_PASS}*'}
          - { line: "{{ datasource_password }}" , regexp: '\${DATASOURCE_PASS}*'}
          - { line: "{{ server_password }}" , regexp: '\${SERVER_PASSWORD}*'}
          - { line: "{{ sftp_password }}" , regexp: '\${SFTP_PASSWORD}*'}
          - { line: "{{ db_userpassword }}" , regexp: '\${DB_PASSWORD}*'}
     roles:
       - basic_role

My Basic_role just prints the items, and I would like to obtain the content of each line:

---

- name: "print password"
  debug: 
    msg: "The content of the line is: {{ item.line}}"
  with_nested:
    - "{{password_text_to_encrypt}}"

But the result that I obtain is:

FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'list object' has no attribute 'line'\n\nThe error appears to have been in.....

If I change item.line to just item, it works but it prints:

ok: [localhost] => (item=[u'regexp', u'line']) => {
    "item": [
        "regexp",
        "line"
    ],
    "msg": "The content of the line is: [u'regexp', u'line']"
}
.
.
.

To summarize, Ansible does not consider the content of line o regexp. I have been doing tests and the variable which are used to init line and regexp are not empty.

2 Answers 2

2

Use with_items instead of with_nested.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the summary version of my problem. What I really want to do is to call an endpoint to encrypt my passwords, but I think it is not necessarily more code. And yes it is copy-paste of another part of my code that actually works.
-1

I think you want loops and includes because you're getting a flattened list which is expected (as per the documentation).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.