ansible-template

Ansible template adds 'u' to array in template

不打扰是莪最后的温柔 提交于 2020-01-10 14:09:47
问题 I have the following vars inside of my ansible playbook I got the following structure domains: - { main: 'local1.com', sans: ['test.local1.com', 'test2.local.com'] } - { main: 'local3.com' } - { main: 'local4.com' } And have the following inside of the my conf.j2 {% for domain in domains %} [[acme.domains]] {% for key, value in domain.iteritems() %} {% if value is string %} {{ key }} = "{{ value }}" {% else %} {{ key }} = {{ value }} {% endif %} {% endfor %} {% endfor %} Now when I go in the

Get first “N” elements of a list in Jinja2 template in Ansible

北城以北 提交于 2020-01-03 19:19:43
问题 Most of my locations have 4+ DNS sources, but a few have less. Each location gets their own dns4_ips list variable like this: dns4_ips: - dns_A - dns_B - dns_C - dns_C My resolv.conf template looks like this: domain example.com search example.com dom2.example.com dom3.example.com {% for nameserver in (dns4_ips|shuffle(seed=inventory_hostname)) %} nameserver {{nameserver}} {% endfor %} The Jinja for loop works great, but in the cases where I have numerous nameservers I'd rather only list the

Get first “N” elements of a list in Jinja2 template in Ansible

大城市里の小女人 提交于 2020-01-03 19:19:31
问题 Most of my locations have 4+ DNS sources, but a few have less. Each location gets their own dns4_ips list variable like this: dns4_ips: - dns_A - dns_B - dns_C - dns_C My resolv.conf template looks like this: domain example.com search example.com dom2.example.com dom3.example.com {% for nameserver in (dns4_ips|shuffle(seed=inventory_hostname)) %} nameserver {{nameserver}} {% endfor %} The Jinja for loop works great, but in the cases where I have numerous nameservers I'd rather only list the

ansible output printing unwanted things. how to format and display only specific data's

谁说我不能喝 提交于 2019-12-24 01:41:31
问题 I am using ansible 2.4 in centos, trying to run the below script in remote servers and getting the output. Here the problem is yum info output is showing with json format also. But i need to display only the output. How to remove the json format. --- - hosts: GeneralServer tasks: - name: Checking the service status shell: systemctl status {{ item }} with_items: - httpd - crond - postfix - sshd register: service - debug: var=service - name: Checking the package info shell : yum info {{ item }}

How can I break the with_items loop based on a condition

和自甴很熟 提交于 2019-12-23 20:27:33
问题 I want to break out of the with_items loop based on a condition. That condition for arguments sake is if the stdout of a command is equal to a particular string. Obviously the example below does not work but this is an idea of what I want to do. For example: - name: testing loop shell: "echo {{ item }}" with_items: - "one" - "two" - "three" register: shell_command # registering the shell command and it's attributes when: shell_command.stdout == "two" # break once the stdout of the run shell

Ansible: Global template folder?

柔情痞子 提交于 2019-12-23 12:17:04
问题 Couldn't find anything google'ing. There is group_vars/all/ for variables. Is there something similar for templates? I would like to use some templates across multiple roles. 回答1: You can put your global templates into templates directory at the top level of Ansible layout (same level as group_vars ). BTW same goes for global files. files/ group_vars/ roles/ site.yml templates/ 回答2: It was possible before 2.2.1, but not after. See issue 20442. There's a patch that allows you to do out-of

Ansible concat vars to string

被刻印的时光 ゝ 提交于 2019-12-18 09:22:38
问题 I've spent most of the day trying to solve this problem and have thus far failed. I am building some playbooks to automate functions in Splunk, and am attempting to convert a list of hosts from an inventory group E.G. [search_head] 1.2.3.4 5.6.7.8 My expected (desired) result from the debug output of the play should be: https://1.2.3.4:8089, https://5.6.7.8:8089 I am attempting to complete this by running the following playbook against a running host: --- - name: Build search head list to

How to get the first element of a list from the output of setup module in Ansible?

▼魔方 西西 提交于 2019-12-17 07:42:34
问题 I received the following data from the setup module: "ansible_nodename": "3d734bc2a391", "ansible_os_family": "RedHat", "ansible_pkg_mgr": "yum", "ansible_processor": [ "AuthenticAMD", "AMD PRO A10-8700B R6, 10 Compute Cores 4C+6G" ], "ansible_processor_cores": 1, "ansible_processor_count": 1, "ansible_processor_threads_per_core": 1, I want to retrieve the 1st value of ansible_processor and use it in a Jinja2 template. If I use {{ ansible_processor }} , it's giving me both values:

Ansible with_dict template use

二次信任 提交于 2019-12-14 00:17:20
问题 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: 8080 backend: http_port: 8081 Finally here is the relevant snippet from server.xml <Connector port="{{ http_port }}" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> What I want to happen is that the relevant http_port gets used in the

Ansible cloudformation update stack

血红的双手。 提交于 2019-12-12 09:42:19
问题 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 cloudformation: stack_name: "{{ stack_name }}" state: present region: "{{ region }}" disable_rollback: false args: template_parameters: CreateAlarms: "{{ create_alarms }}" When I run it, the play throws an error stating that it expects values for