替换正则表达式Ansible中的嵌套变量[模板错误

时间:2019-01-08 10:45:30

标签: ansible jinja2

我有以下任务:

  File "<ipython-input-56-2da0ffaf5447>", line 1, in <module>
    train()

  File "C:/Users/user/Desktop/dantitanic/AnotherTest.py", line 41, in train
    classifier.fit(X_train, y_train)

  File "C:\Users\user\Anaconda3\lib\site-packages\sklearn\linear_model\base.py", line 458, in fit
    y_numeric=True, multi_output=True)

  File "C:\Users\user\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 756, in check_X_y
    estimator=estimator)

  File "C:\Users\user\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 552, in check_array
    "if it contains a single sample.".format(array))

执行我时出现以下错误:

pre_tasks:
- name: Disable nodes from the load balancer
  replace:
    path: "/USR/{{ ansible_user }}/{{ apache_directory }}/conf.d/balancers.conf"
    regexp: 'BalancerMember.*{{ balancer_members.[item].http.[inventory_hostname].url }}.*'
    replace: '#BalancerMember.*{{ balancer_members.[item].http.[inventory_hostname].url }}.*'
  with_items:
    - "portail_cluster"
    - "portail_cluster_se"
    - "portail_cluster_pentaho"
    - "ws_cluster"
    - "portail_longtimeout"
    - "portail_core"
  delegate_to: groups.front
  register: result

有人可以理解这种语法的问题吗? 在此先感谢^ _ ^!

2 个答案:

答案 0 :(得分:0)

我相信变量的扩展仅发生在""中的字符串中,而不发生在''中的字符串中。

Ansible documentation - YAML Gotchas

中对此进行了简要描述

答案 1 :(得分:0)

我发现了问题,这是语法问题,我更改了text。[varibl] .text和text [variable] .text。 解决方法如下:

 - name: Disable web nodes from the load balancer
      replace:
        path: "/USR/{{ ansible_user }}/{{ apache_directory }}/conf.d/balancers.conf"
        regexp: "^ *BalancerMember.*{{ balancer_members[item].http[inventory_hostname].url }}.*"
        replace: "    #BalancerMember {{ balancer_members[item].http[inventory_hostname].url }}"
      delegate_to: server-ip