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
2 answers

ansible openssl_csr creation with dynamic CN and alt_namess list

I'm creating private key and csr file through ansible. im stuck on how do i pass CN and alt names(comma separated list) to ansible playbook. manual command and config file. openssl req -new -sha256 -nodes -out NEW.csr -newkey rsa:2048 -keyout…
user13562350
0
votes
2 answers

ansible output mail with line break

I've got a awk output - name: read files shell: awk -F "|" 'FNR==NR {lines[$1]=$2; next} $9 in lines {print lines[$9], "on", $2}' file1 file2 register: resultawk - debug: msg: "{{ resultawk.stdout.split('\n') }}" this prints…
javierccs
  • 1
  • 1
  • 3
0
votes
1 answer

Generate Ansible template variable only once

Context I have an Ansible template that creates a configuration file. Most variables used by this template come from some stable source, such as variables defined in the playbook. However one variable contains a secret key which somehow needs to be…
Jeroen De Dauw
  • 10,321
  • 15
  • 56
  • 79
0
votes
0 answers

looping ansible registered results in jinja template

I will have a output from one of the task is like, "msg": [ "colours", "fruits", "animals", "people", "men" ] using the above list, in another task it will return the associated results in…
user8096150
0
votes
1 answer

Change parameters in command lines with item

We need to create a standard ansible that will change only one parameter for specific commands in a specific table ex: cmd: Sys; Cl; Codes; DPlan; Entry; get 1 PLO from {{ item.a }}; y cmd: Sys; Cl; Codes; DPlan; Entry; get 1 PLO {{ item.b }} 12L;…
0
votes
1 answer

Ansible - Json_Path does not seem to work

I have the following set_fact task: - set_fact: task_uuid: "{{ task_status.json |lower |to_json | from_json |json_query('taskuuid') }}" This is what I have for the task_status.json: debug: var: task_status.json { "task_status.json": { …
Vijay Nidhi
  • 161
  • 1
  • 1
  • 9
0
votes
1 answer

How to change "parse_cli_textfsm" to reference template folder in role folder in Ansible?

GOAL I want to create a portable role folder that utilizes textfsm templates in role directory. Directory structure $ tree . ├── ansible.cfg ├── hosts.ini ├── out_pb1 ├── pb1.yml ├── roles │   ├── command_facts │   │   ├── tasks │   │   │   └──…
kstack
  • 1
0
votes
0 answers

How to generate files from a list with dictionaries, each dictionary into a separate file according to the template?

The task is to generate dns zone files, each zone in a separate file. Is it possible to somehow complete this task with modules, or will I have to write something of my own? I'm stuck here: List with dict: bind_zones: - name: "example.com" …
XAOc
  • 13
  • 4
0
votes
1 answer

YAML List Filtering

Could someone please assist me on the below: Either ok: [localhost] => { "tag_info": { "changed": false, "msg": "All items completed", "results": [ {"vm_list": [ "NSY6TFSANSBL01"]}, ] OR ok:…
0
votes
1 answer

Render an ansible templated json file without comments

I have a templated json file foo.json.j2 which has lots of documentation ("json with comments"). On the server that file must not contain comments. Is there a way (or module) I can use to render the template without comments? I can obviously do this…
lonix
  • 14,255
  • 23
  • 85
  • 176
0
votes
0 answers

Ansible default value not reached when using variable concatenation

my_var: "{{ url_var+'/' | default(default_url_var) }}" I have the above code but when I run it, it errors out when url_var is not set saying 'url_var' is undefined. I want the default value to be taken if url_var is not defined. I believe whats…
0
votes
1 answer

skip multiple values for loop which is passing to a task ansible

how can I filter out unwanted values from loop which are passed from register output (from previous task) code # assume the list_one below register values. list_one = [root, a, b, c] - name: with_together debug: msg: "{{ item.0 }} - {{ item.1…
0
votes
1 answer

How can I use nested variables in ansible to dynamically set the hostgroup the playbook runs on?

I am new to ansible and cant seem to figure this out. I have a playbook that configures a bunch of kubernetes objects. The hosts value should be interpolated dynamically. Ansible doesn't permit nesting of variables so I am not sure how to get this…
sdhir
  • 41
  • 7
0
votes
1 answer

How to combine a fileglob within a loop

Until today I had only ONE type specific xml file ~/files: gg-schema.xml.j2 lr-schema.xml.j2 and I copied it with template module like this: - hosts: localhost gather_facts: false vars: types: - lr - gg …
901Franco
  • 11
  • 3
0
votes
2 answers

How to specify become password for tasks delegated to localhost

I have a playbook that targets a particular host. But there are few tasks that I need to execute locally, so i am using "delegate_to" for those tasks. A few locally delegated tasks require sudo privileges, so I used "become: yes" and passed…
Aman Soni
  • 3
  • 3