【问题标题】:Ansible - Windows path variableAnsible - Windows 路径变量
【发布时间】:2019-05-07 12:31:59
【问题描述】:

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

#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

当然有一个简单的答案,但一时找不到

【问题讨论】:

  • 您必须引用 Windows 路径分隔符。

标签: windows path ansible


【解决方案1】:

path 的声明应使用单引号 (')。那么反斜杠 (\) 将不会被解释为转义字符。见Gotchas

单引号和双引号的区别在于双引号中可以使用转义符

path: '{{ directory_path }}\AppName-{{ env }}'

代码缩进错误。正确的语法如下

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 测试 playbook 是个好主意。

【讨论】:

  • 感谢弗拉基米尔,这是我的问题,如何审查做出了这些更改,现在一切似乎都很好。刚刚看了一下 ansible-lint - 将考虑合并它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-02
  • 2016-03-05
  • 2017-10-28
相关资源
最近更新 更多