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
1 answer

Ansible create template in loop with access to item

I'm trying to dynamically create a new nginx host for each item found in an array. However, I need to know the details of the loop. - name: 'adding sites to nginx' template: src: 'nginx/template.conf.j2' dest: '/etc/nginx/conf.d/{{ item…
Jacob Haug
  • 509
  • 1
  • 9
  • 18
0
votes
1 answer

Ansible/Jinja2 nested escaping

Is there any way to have nested escaping of jinja2 template? replace: path: /etc/my_file regexp: '^my_var = ""' replace: !unsafe "my_var = {{getv '/{{ variable}}/my_dir/my_file'}}" I'd like to replace my_var = "" with my_var = {{getv…
0
votes
0 answers

Ansible tower inventory name regex

I'm working on the project and I'm stuck right now. My question is I'm trying to deploy aws lambda function using ansible tower temple and we have multiple aws account but naming standard include dev or prod. Is there a way and any example that…
0
votes
1 answer

registering variables from stdout using regex_search

I have followed numerous related thread on this subject, and am likely close, but not yet. Sending URI GET to Infoblox IPAM tool to look up IP Address for deletion. IPAM tool sends back a reference object code used to make a put call back to delete.…
RobWieters
  • 43
  • 4
0
votes
1 answer

failed to install dnspython with ansible playbook

Team, I have my playbook as below and i tried with become: yes as well but no luck. how to get around this ? - easy_install: name: dnspython state: present #become: yes - name: Validate DNS record lookup for…
AhmFM
  • 1,552
  • 3
  • 23
  • 53
0
votes
1 answer

How can I upload the Ansible template to a different server than the one running against?

I have an Ansible role run against X' number of servers and what I want to achieve is to have the Template upload to a different server. I want to have all 'reports' from all tasks to a template file, but I want that template file to be hosted on a…
spiros_m
  • 41
  • 1
  • 4
0
votes
1 answer

failed_when with msg in ansible

I am trying to validate the result of a lookup done via dig, but I am receiving a error. Could someone help me? - name: Simple A record (IPV4 address) lookup for {{ kubeapi_server }} debug: msg="{{ lookup('dig', '{{ kubeapi_server }}' )}}" -…
AhmFM
  • 1,552
  • 3
  • 23
  • 53
0
votes
0 answers

unable to fetch a binary path with ansible shell module

Team, Works locally on my laptop manually but fails only when calling via ansible. Is ansible looking at it in different shell? I have ansible controller as MAC book. I am trying to store the path of a binary in register variable but shell command…
AhmFM
  • 1,552
  • 3
  • 23
  • 53
0
votes
1 answer

grep url from text and access in ansible

Team, I have a text file containing the url that I need to launch using uri anisible module and capture its result to check http_status code is 200 or not. my playbook is below but I am getting error: The same work when I use a defined variable…
AhmFM
  • 1,552
  • 3
  • 23
  • 53
0
votes
1 answer

How to fetch nested variable in ansible template?

How do I get the variable which is nested as below: mongoservers: - mongo_master: dev_01 label: mongomaster dev01 urls: - mongomaster01.dev.local.net - mongomaster02.dev.local.net - mongo_master: dev_02 label: mongomaster dev02 …
shrish
  • 408
  • 2
  • 8
  • 22
0
votes
1 answer

Ansible : how to run multiple steps shell command with special chars

Under my Playbook , i want to run a shell command which is the following : for STACK in stackone stacktwo;do docker stack ps --format "table {{.ID}}\t{{.Name}}\t{{.CurrentState}}\t{{.Error}}\t{{.Node}}" $STACK | (read -r; printf "%s\n" "$REPLY";…
firasKoubaa
  • 6,439
  • 25
  • 79
  • 148
0
votes
2 answers

How to access ip_address from inventory for a specific host?

Inventory looks like: [host-1] h1 ansible_ssh_private_key_file="*/*/*" ansible_host=a.b.c.d h2 ansible_ssh_private_key_file="*/*/*" ansible_host=a.b.c.t [host-2] h3 ansible_ssh_private_key_file="*/*/*" ansible_host=a.b.c.r I want…
7wick
  • 411
  • 4
  • 17
0
votes
1 answer

Ansible variable substitution in combination with task delegation

I'm running into a problem where a registered variable is incorrectly substituted in a subsequent task that is delegated to another host. This is the stripped down version of my playbook: - hosts: all name: Test Play gather_facts: false …
Makkes
  • 1,768
  • 15
  • 19
0
votes
1 answer

What does it mean and how to fix Ansible error " 'NoneType' object has no attribute 'read' "?

I am trying to install MySql 5.7 version through Ansible, but it is saying fatal: [192.168.1.45]: FAILED! => {"changed": false, "failed": true, "msg": "Failure downloading http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm,…
Asad Ali
  • 389
  • 1
  • 10
  • 28
0
votes
2 answers

Is it possible to merge anisible group_vars, if possible can you hlep me how to solve

Actually I have group_vars, I need to merge those vars, can you help me. group_vars/eu/main.yaml mgmt_routes: Tok: - ip: 172.22.203.253 netmask: 255.255.255.255 group_vars/all/main.yaml mgmt_routes: all: - ip: 172.18.0.70 …