2017-01-17 4 views
3

文字列をapp_name: <anything>からapp_name: {{ node }}に置き換える必要があります。文字列を正規表現で置換するAnitoryで置換モジュールを使用する

置き換える:DEST =/ABC/HYBRIS/newrelic/newrelic.yml正規表現= 'APP_NAMEを:\ S [A-ZAの下交換モジュールを使用して実行しようとしながら

いくつかの構文エラーがあります-z0-9] * APP_NAME」=置き換える ': "{{}}ノードを"'

エラーメッセージ:

[[email protected] ansible]$ ansible-playbook -i hosts_acc ACC.yml --tags=newrelic 
ERROR! Syntax Error while loading YAML. 


The error appears to have been in '/ABC/Ansible/roles/NewRelic_Base/tasks/main.yml': line 12, column 101, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

- name: NewRelic - Replace app_name variable 
    replace: dest=/ABC/hybris/newrelic/newrelic.yml regexp='app_name:\s[A-Za-z0-9 ]*' replace="app_name: {{ node }}" 
                            ^here 
We could be wrong, but this one looks like it might be an issue with 
missing quotes. Always quote template expression brackets when they 
start a value. For instance: 

    with_items: 
     - {{ foo }} 

Should be written as: 

    with_items: 
     - "{{ foo }}" 
+0

、あなたは' template'を使用し、全体のことを書く必要があります。 – tedder42

答えて

3

問題あなたの例では、コロンは、内部空間が続いています可能な表記法(w i等号)、それを回避するにはいくつかの方法があります。 Ansible表記this GitHub threadを参照してアイデアを

tasks: 
    - replace: 
     dest: ./src 
     regexp: 'app_name:\s[A-Za-z0-9 ]*' 
     replace: 'app_name: {{ node }}' 

私のアドバイスはYAML構文を使用することです。

例:代わりに `replace`の

- replace: dest=./src regexp='app_name:\s[A-Za-z0-9 ]*' replace='app_name{{ ":" }} {{ node }}' 
- replace: dest=./src regexp='app_name:\s[A-Za-z0-9 ]*' replace='app_name:{{ " " }}{{ node }}' 
- replace: "dest=./src regexp='app_name:\s[A-Za-z0-9 ]*' replace='app_name: {{ node }}'" 
関連する問題