ansible-template

Ansible variable in key/value key

谁说胖子不能爱 提交于 2021-02-20 13:44:32
问题 I'm passing env variables to a Docker container in an ansible playbook, how do I set an Ansible variable in the key in the key/value of an env? So this: - name: webproxy container docker_container: name: "webproxy" image: "webproxy" env: SERVICE_443_NAME: "webproxy" becomes this: - name: webproxy container docker_container: name: "webproxy" image: "webproxy" env: SERVICE_{{ port_number }}_NAME: "webproxy" 回答1: Use JSON notation to define a dictionary with environment variables: - name:

How to specify become password for tasks delegated to localhost

依然范特西╮ 提交于 2021-01-29 17:27:27
问题 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 --ask-become-pass through command line and it worked fine. But now when I have created a job on ansible tower, how do I manage to provide become password for the user(i guess awx user) that is running the job??? 回答1: You'll want to set the special variable

AnsibleError: template error while templating string: expected token ':', got '}'

北慕城南 提交于 2021-01-27 22:03:32
问题 An error occurs when preparing the template. Who can tell you how to fix it? Variables, if necessary, can also be edited. vars: AllСountry: - "name1" - "name2" name1: - "region1a" - "region1b" name2: - "region2a" - "region2b" Code {% for country in AllСountry %} {name: "{{ country }}",{% for count in {{ country }} %}My country = {{ count }} {% endfor %}{% endfor %} the result is an error AnsibleError: template error while templating string: expected token ':', got '}' Yes in the end I expect

Is there a way to override a template defined into an ansible galaxy role?

六眼飞鱼酱① 提交于 2021-01-02 07:56:37
问题 I'm trying to set up a server with ansible and I'd like to use this galaxy role. It defines a template that I'd like to customize, but I don't know how. Right now I defined the role into requirements.yml and I installed it using: ansible-galaxy install -r requirements.yml which installed the role somewhere on my system. I tried by recreating the folder tree into my repository where I store my playbooks: roles |- ansible-role-passenger |- templates |- passenger.j2 but it does not work. When I

Can ansible variables be used to declare hosts in a playbook?

ぃ、小莉子 提交于 2020-12-06 03:43:48
问题 I have a playbook in the format below: --- - hosts: myIP tasks: - name: Install a yum package in Ansible example yum: name: ThePackageIWantToInstall state: present where myIP and ThePackageIWantToInstall are variables. When the job template runs, I would like the user in the extra variables popup to be able to go with: myIP = 192.168.1.1 ThePackageIWantToInstall = nano As the documentation doesn't provide an example of supplying a variable via a job template, is this possible? 回答1: Yes. -

Can ansible variables be used to declare hosts in a playbook?

被刻印的时光 ゝ 提交于 2020-12-06 03:40:29
问题 I have a playbook in the format below: --- - hosts: myIP tasks: - name: Install a yum package in Ansible example yum: name: ThePackageIWantToInstall state: present where myIP and ThePackageIWantToInstall are variables. When the job template runs, I would like the user in the extra variables popup to be able to go with: myIP = 192.168.1.1 ThePackageIWantToInstall = nano As the documentation doesn't provide an example of supplying a variable via a job template, is this possible? 回答1: Yes. -

Can ansible variables be used to declare hosts in a playbook?

做~自己de王妃 提交于 2020-12-06 03:40:17
问题 I have a playbook in the format below: --- - hosts: myIP tasks: - name: Install a yum package in Ansible example yum: name: ThePackageIWantToInstall state: present where myIP and ThePackageIWantToInstall are variables. When the job template runs, I would like the user in the extra variables popup to be able to go with: myIP = 192.168.1.1 ThePackageIWantToInstall = nano As the documentation doesn't provide an example of supplying a variable via a job template, is this possible? 回答1: Yes. -

Ansible: get current target host's IP address

夙愿已清 提交于 2020-05-09 17:44:48
问题 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 }}" 回答1: A list of all addresses is stored

Ansible, set_fact using if then else statement

冷暖自知 提交于 2020-01-12 08:04:10
问题 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. 回答1: Firstly, dictionaries in YAML are not ordered (and the syntax used by Ansible here is a

Ansible, set_fact using if then else statement

隐身守侯 提交于 2020-01-12 08:04:06
问题 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. 回答1: Firstly, dictionaries in YAML are not ordered (and the syntax used by Ansible here is a