Ansible - Windows 路径变量 [英] Ansible - Windows path variable

查看:16
本文介绍了Ansible - Windows 路径变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以同时使用变量和字符串吗?例如,我想定义我的路径和其他结合变量和字符串的选项?

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 的声明应使用单引号 (').然后反斜杠 (\) 不会被解释为转义字符.请参阅问题

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆