ansible-template

Ansible cloudformation update stack

拜拜、爱过 提交于 2019-12-05 12:51:38
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 the other template params. From the ansible documentation here http://docs.ansible.com/ansible/latest

ansible template add value to list -

二次信任 提交于 2019-12-04 23:16:09
问题 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 be: server_name: "actual.domain.com alias1.domain.com alias2.domain.com" so , I tried the following jinja2 script ... {% if item.aliases is defined %} {% set servername = [ item.target ] %} {% for alias in item.aliases.iteritems() %} {% if alias|length > 0 %} {%

How to remove or exclude an item in an Ansible template list?

泄露秘密 提交于 2019-12-04 18:19:22
问题 I'm writing an Ansible template that needs to produce a list of ip's in a host group, excluding the current hosts IP. I've searched around online and through the documentation but I could not find any filters that allow you to remove an item in a list. I have created the (hacky) for loop below to do this but was wondering if anyone knew a "best practice" way of filtering like this. {% set filtered_list = [] %} {% for host in groups['my_group'] if host != ansible_host %} {{ filtered_list

Ansible iterate over hosts in inventory group set by variable

怎甘沉沦 提交于 2019-12-04 06:48:57
问题 I have the next snippet in my role template: upstream portal { {% set nodes = groups["my_dev_cluster"] %} {% for node in nodes %} ...do something with nodes... {% endfor %} } And it works well. But when I try to parametrize inventory group name like this: upstream portal { {% set nodes = groups["{{cluster_name}}"] %} {% for node in nodes %} ...do something with nodes... {% endfor %} } I get an exception like: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable:

Ansible and Jinja2 logic for loops

懵懂的女人 提交于 2019-12-04 05:27:26
问题 Variable file createuser : userslist: - da_cel_upload - da_tag_upload Ansible logic: - include_vars: group_vars/createuser - name: Create custom file /etc/ssh/shhd_config for user configuration and restart sshd service template: src=sshconfig.j2 dest=/etc/ssh/sshd_config with_items: '{{userslist}}' notify: restart ssh Contents of sshconfig.j2 : Match User {{ item }} {% raw %}ChrootDirectory /home/{% endraw %}{{ item }} X11Forwarding no AllowTcpForwarding no ForceCommand internal-sftp Output I

Ansible, set_fact using if then else statement

倖福魔咒の 提交于 2019-12-03 15:57:45
I am trying to set a variable in Ansible with set_fact at runtime based upon another variable. If uses first value no matter what the actual value is. Here is my code example: - name: Global_vars - get date info set_fact: jm_env: "{{lookup('env', 'Environment')}}" l_env: "{% if '{{jm_env}}==Develop' %}d{% elif '{{jm_env}}==Staging'%}s{% else %}p{% endif %}" l_env is d no matter what jm_env is set. Firstly, dictionaries in YAML are not ordered (and the syntax used by Ansible here is a YAML dictionary), so you have no guarantee Ansible would first set jm_env before proceeding to l_env -- you

Ansible with_dict template use

▼魔方 西西 提交于 2019-12-03 15:41:46
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 template module. But instead I get and error: fatal: [localhost] => {'msg': "AnsibleUndefinedVariable: One or

Ansible template adds 'u' to array in template

两盒软妹~` 提交于 2019-12-03 06:20:23
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 VM and see the file I get the following: Output [[acme.domains]] main = "local1.com sans = [u'test

ansible - delete unmanaged files from directory?

旧城冷巷雨未停 提交于 2019-12-03 01:29:12
问题 I want to recursively copy over a directory and render all .j2 files in there as templates. For this I am currently using the following lines: - template: > src=/src/conf.d/{{ item }} dest=/dest/conf.d/{{ item|replace('.j2','') }} with_lines: find /src/conf.d/ -type f -printf "%P\n" Now I'm looking for a way to remove unmanaged files from this directory. For example if I remove a file/template from /src/conf.d/ I want Ansible to remove it from /dest/conf.d/ as well. Is there some way to do

Ansible: get current target host's IP address

我的未来我决定 提交于 2019-12-02 17:02:46
How do you get the current host's IP address in a role? I know you can get the list of groups the host is a member of and the hostname of the host but I am unable to find a solution to getting the IP address. You can get the hostname by using {{inventory_hostname}} and the group by using {{group_names}} I have tried things like {{ hostvars[{{ inventory_hostname }}]['ansible_ssh_host'] }} and ip="{{ hostvars.{{ inventory_hostname }}.ansible_ssh_host }}" A list of all addresses is stored in a fact ansible_all_ipv4_addresses , a default address in ansible_default_ipv4.address . --- - hosts: