Questions tagged [ansible-template]

Use this tag for questions regarding writing and processing Ansible templates, Jinja2 syntax within Ansible, custom filters.

Ansible templates are processed by the Jinja2 templating language. Beside the default Jinja2 filters Ansible extends functionality with a lot of custom filters.

Templates are rendered from Ansible tasks through the template module or through the template lookup plugin.

638 questions
7
votes
1 answer

'dict object' has no attribute 'stdout' in Ansible Playbook

My playbook: - name: JBoss KeyStore and Truststore passwords will be stored in the password vault #shell: less "{{ vault }}" shell: cat "{{ vault }}" register: vault_contents tags: - BW.6.1.1.10 with_items: …
anish anil
  • 2,299
  • 7
  • 21
  • 41
7
votes
2 answers

Ansible variable in key/value key

I'm passing env variables to a Docker container in an ansible playbook, how do I set an Ansible variable in the key in the key/value of an env? So this: - name: webproxy container docker_container: name: "webproxy" image: "webproxy" …
Alex Laverty
  • 485
  • 1
  • 7
  • 16
7
votes
2 answers

ansible template add value to list -

based on the following ansible playbook values .. target: "actual.domain.com" aliases: - "alias1.domain.com" - "alias2.domain.com" I am trying to setup an ansible template to produce the nginx server_name which in this case should…
user762579
6
votes
1 answer

How to fix 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'value' error

I have defined the nginx_upstreams variable in a different role that in turn uses the geerlingguy.nginx role and I have also specified the "name", "strategy" and the "servers", but when I run this role, ansible throws the error given below as if it…
6
votes
1 answer

Variable as a YAML tree. How to save indent?

I have yml file with template. Template is a part of keys started from a middle of yml tree. Templating works is ok, but indent is saved only for last key. How to save indent for all keys? base.yml: app: config1: base: {{…
jimmbraddock
  • 867
  • 2
  • 8
  • 17
6
votes
1 answer

Ansible template module not parsing with_items variable

I am using a simple template with only variables in it. This is how my task looks like in my playbook (actually a role being used from my playbook): - name: Ensure the conf file exists template: src: file.conf.j2 dest: '/opt/file.conf' …
felichas
  • 77
  • 1
  • 1
  • 4
6
votes
1 answer

ansible conditional templates

I want to have a simple if else condition in ansibles jinja templates. For plain python cluster_name+'A' if isCondition is True else cluster_name +'B' wors great if the following variables are defined: isSingleNode = True cluster_name =…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
6
votes
1 answer

How to concatenate files with a glob pattern as a single value?

I have a fairly simple playbook which creates authorized_keys entries for a given user in Ansible: - name: chat user authorized keys authorized_key: user: chat key: | {% for filename in lookup('fileglob', 'public_keys/*.pub')…
Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
6
votes
1 answer

Ansible with_dict template use

I have the following task: - name: copy server.xml template: src=server.xml dest=/var/containers/{{ item.key }}/conf with_dict: containers And I've also added the containers dictionary in my group_vars containers: frontend: http_port:…
user1432403
  • 1,533
  • 4
  • 16
  • 21
5
votes
1 answer

How to get interpolated value of variable in Ansible / Jinja2

I'm trying to define Ansible variables this way: user: name: First Last nick: '{{ vars["user"]["name"] | regex_replace("\W", "_") }}' email: '{{ vars["user"]["nick"] }}@example.com' And the result email is: "{{ vars[\"user\"][\"name\"] |…
5
votes
1 answer

In Ansible Jinja template, How to escape single quote which is inside the double quote?

In Ansible role, I'm using Jinja template to create a file with fetching value from a variable. Contents of vars file vars/main.yml from where variables are being fetched in jinja template: Header: - key: a-b-c action: xxx option: '"xyz 'ZZZ'…
kishs1991
  • 969
  • 4
  • 10
  • 16
5
votes
1 answer

Could not find or access a file that is in the local directory

I have got an error in my project, when I am trying to copy from local directory to remote one error message: fatal: [xxx]: FAILED! => { "changed": false, "msg": "could not find…
StyleZ
  • 1,276
  • 3
  • 11
  • 27
5
votes
1 answer

Ansible Tower: How to pass job number into playbook?

I have written an Ansible playbook that needs as one of its parameters the job number that is running it so that I make add a reference to the job to a database that I maintain. How can I get the Tower template to pass this to the playbook? Here is…
user11466558
  • 127
  • 3
  • 10
5
votes
1 answer

Ansible cloudformation update stack

I'm trying to update a cloudformation stack with just a param value that I need to change via Ansible. The stack is previously created and has about 20 input params, but I just need to update the value for one. I tried the following: - name: update …
5
votes
1 answer

How to Sort Items from an Ansible with_subelements list

I am using with_subelements to loop over some nested data. I would like to loop over the nested elements but sort the second level of data when it is iterated over. - name: Can I haz sorted nested elements? debug:…
Randy
  • 908
  • 12
  • 30
1 2
3
42 43