Ansible-Windows路径变量 [英] Ansible - Windows path variable
问题描述
是否可以同时使用变量和字符串?例如,我想定义变量和字符串相结合的路径和其他选项?
Is there away to use variables and string together? For example I would like to, define my path's and other options combining variables and string?
#Add Directory
- name: Add Directory
win_file:
path: "{{directory_path}}\AppName-{{env}}"
state: directory
#Add IUSR to directory path
- name: ADD IUSR
win_acl:
path: "{{directory_path}}\AppName-{{env}}"
user: IUSR
rights: Read
type: allow
state: present
propagation: 'NoPropagateInherit'
#Add website
- name: "{{env}} Add App Name"
win_iis_website:
name: "AppName-{{env}}"
state: started
port: 80
ip: "{{serverip}}"
hostname: "appname-{{env}}.com"
application_pool: "{{application_pool4}}"
physical_path: "{{directory_path}}\AppName-{{env}}"
register: website
当然有一个简单的答案,但一时找不到答案
Sure there is a simple answer but can't find one at the minute
推荐答案
path 的声明应使用单引号(').然后,反斜杠(\)不会被解释为转义字符.请参见 Gotchas
The declarations of path shall be single-quoted ('). Then the backslash (\) won't be interpreted as an escape character. See Gotchas
单引号和双引号之间的区别在于,在双引号中可以使用转义符
The difference between single quotes and double quotes is that in double quotes you can use escapes
path: '{{ directory_path }}\AppName-{{ env }}'
代码缩进是错误的.正确的语法如下
The indentation of the code is wrong. The correct syntax is below
tasks:
#Add Directory
- name: Add Directory
win_file:
path: '{{ directory_path }}\AppName-{{ env }}'
state: directory
#Add IUSR to directory path
- name: ADD IUSR
win_acl:
path: '{{ directory_path }}\AppName-{{ env }}'
user: IUSR
rights: Read
type: allow
state: present
propagation: 'NoPropagateInherit'
#Add website
- name: "{{ env }} Add App Name"
win_iis_website:
name: "AppName-{{ env }}"
state: started
port: 80
ip: "{{ serverip }}"
hostname: "appname-{{ env }}.com"
application_pool: "{{ application_pool4 }}"
physical_path: '{{ directory_path }}\AppName-{{ env }}'
register: website
用 ansible-lint 测试剧本是个好主意.
It's a good idea to test the playbooks with ansible-lint.
这篇关于Ansible-Windows路径变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!