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
0
votes
0 answers

copy multiple output stream to a file in ansible

I am pulling network switches interfaces information e.g. interface name, admin status, description etc. and parsing those values into a single .csv file but it seems like it is overwriting a file rather than appending a file, can you please let me…
0
votes
1 answer

How to remove the comma at the end of the line in ansible-template?

Can you tell me how to remove the comma at the end of the line? Final output: {name: "name1", My country = "region1a", My country = "region1b"}, {name: "name2", My country = "region2a", My country = "region2b"}, you only need to delete one…
Alex alex
  • 116
  • 1
  • 1
  • 7
0
votes
1 answer

Alternative to templating inside `when` when trying to dynamically form a conditional

I am trying to dynamically create a conditional by declaring the following variable in_tags: in ansible_run_tags or "all" in ansible_run_tags and use it in a when condition like so - include: zsh.yml when: '"zsh" {{ in_tags }}' However Ansible…
0
votes
0 answers

Source a file and variable globally across the playbook

I have following file that I need to source in multiple plays in a playbook. --- - hosts: all tasks: - shell: source /foo/bar && export API_VER=4 && blah123 - shell: source /foo/bar && export API_VER=4 && blah456 - shell: source /foo/bar…
smc
  • 2,175
  • 3
  • 17
  • 30
0
votes
1 answer

Increment a Byte in an IP address

Really simple thing I want to do in Ansible ... or so you would think. All I want to do is to set a variable [which I later use in a j2 template] to the value of ansible_default_ipv4.network, with the last byte chopped off and third incremented. so,…
0
votes
0 answers

how can I parse this output to Json format

- hosts: localhost gather_facts: no vars: output: | Routing entry for 2001:506:4200:4000::/50 Known via "static", distance 1, metric 0 (connected) Installed Aug 12 12:39:44.252 for 8w6d …
Raghu
  • 43
  • 8
0
votes
1 answer

How to rename a file in ansible

I need to rename hosts_example or hosts_Example to be named as hosts_real if any of the file exists - name: Playbook to Standardize Hosts hosts: test vars: destpath: /etc/hosts_real filename: [ /etc/hosts_example,/etc/hosts_Example ] …
celcoprab
  • 35
  • 1
  • 7
0
votes
1 answer

Split debug variable output into two separate variables in ansible

I am using below code snippet where image details would be printed: - set_fact: image_name: "{{ load.results|map(attribute='stdout_lines')|list }}" - debug: var: image_name Output: TASK [set_fact]…
sanjibn
  • 11
  • 2
0
votes
0 answers

Ansible: Appending to the dictionaries skips duplicated key names

I'm trying to populate dictionary from register output result.containers which happens to override the item.Image with same value. Here is my output. "result.containers": [ { "Image": "lna-docker/webproxy:2.4.0", "Names": [ …
Sara James
  • 133
  • 1
  • 14
0
votes
1 answer

Can I render ansible templates to a variable vs. to disk?

Is writing a file the only way to render an ansible template? In the past, with python and jinja2, I've rendered jinja templates to python vars directly and was hoping I can do the same with ansible. What I'm trying to do is take the content of my…
user797963
  • 2,907
  • 9
  • 47
  • 88
0
votes
2 answers

ansible how to use custom script to become root

I have read that "--become-user=root" using ansible adhoc command and playbook has also similar type task is being is used. My problem is , in our provisioned vms , we don't have privilege to become root using sudo command we have custom script to…
Suman g
  • 477
  • 3
  • 14
0
votes
1 answer

create Azure release pipeline using ansible

Whether ansible can be used to create release and build pipelines in azure is there any existing or custom modules for creating pipelines?
0
votes
1 answer

How to specify log per task on ansible playbook

I have 1 roles with 14 tasks, when running roles, they will run 14 tasks in turn, and the results return all 14 tasks, is there any other way for me to have each task have a separate log file in ansible? ? If possible please show me the example,…
0
votes
1 answer

How to copy files to a destination with variable in ansible?

I have a destination for file copy as a variable file_path, how can I copy files to that destination using template/copy modules? Tried: --- - hosts: localhost connection: local tasks: - name: variable command: echo "emptyDir" …
r0r0n0a
  • 173
  • 2
  • 2
  • 10
0
votes
1 answer

Using with_items in Variable in Ansible

In the below code I am using Ansible template, copying it to multiple locations. The template also has a variable in it : {{user}}. This should be replaced with - imail1,imail2,imail3,imail4 respectively. item.user is not getting substituted for…