FAQ
I tried to change one line in a file with lineinfile command, but it looks
like this command does not resolve variables. See my playbook snippet below

#in my playbook, {{ kibana_doc_root }}, {{ kibana_version }},
{{kibana_config_file}}, {{elasticsearch_URL}}, {{ elasticsearch_port }}
have been defined

The following snippet can successfully change the file content in
config.js, but {{elasticsearch_URL}} is not resolved (i.e. the line shows
{{elasticsearch_URL}} as is):

----- Snippet 1 -------------
- name: debug variables
   debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
kibana_version }}/{{kibana_config_file}}"

- name: Replace the URI of the ElasticSearch service in config.js on Kibana
server
   lineinfile:
     dest=/var/www/kibana/kibana-3.0.0milestone4/config.js
     regexp="(elasticsearch.* \"http.*)$"
     state=present
     line="elasticsearch':' \" {{ elasticsearch_URL }}:{{ elasticsearch_port
}} \" "
--------------------






The following snippet cause an error of "failed: [kibana] => {"failed":
true, "item": "", "rc": 257}
msg: Destination
{{kibana_doc_root}}/{{kibana_version}}/{{kibana_config_file}} does not
exist !"

----------------- Snippet 2 --------
- name: debug variables
   debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
kibana_version }}/{{kibana_config_file}}"

- name: Replace the URI of the ElasticSearch service in config.js on Kibana
server
   lineinfile:
     dest="{{ kibana_doc_root }}/{{ kibana_version }}/{{kibana_config_file}}"
     regexp="(elasticsearch.* \"http.*)$"
     state=present
     line="elasticsearch':' \" {{ elasticsearch_URL }}:{{ elasticsearch_port
}} \" "
--------------------------------


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c05b0e63-ea8c-4e17-8f13-2968b068ec81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Michael DeHaan at Jul 21, 2014 at 11:13 pm
    A quick question or to -- what version of Ansible are you trying this on?

    In your ansible.cfg, is this perhaps an upgrade that does not have "fail on
    undefined variables" turned on?

    Most people have this on now, but not all. It's the default if you don't
    have an ansible.cfg and your version is new enough.

    On Mon, Jul 21, 2014 at 2:47 PM, Sean wrote:

    I tried to change one line in a file with lineinfile command, but it looks
    like this command does not resolve variables. See my playbook snippet below

    #in my playbook, {{ kibana_doc_root }}, {{ kibana_version }},
    {{kibana_config_file}}, {{elasticsearch_URL}}, {{ elasticsearch_port }}
    have been defined

    The following snippet can successfully change the file content in
    config.js, but {{elasticsearch_URL}} is not resolved (i.e. the line shows
    {{elasticsearch_URL}} as is):

    ----- Snippet 1 -------------
    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{kibana_config_file}}"

    - name: Replace the URI of the ElasticSearch service in config.js on
    Kibana server
    lineinfile:
    dest=/var/www/kibana/kibana-3.0.0milestone4/config.js
    regexp="(elasticsearch.* \"http.*)$"
    state=present
    line="elasticsearch':' \" {{ elasticsearch_URL }}:{{
    elasticsearch_port }} \" "
    --------------------






    The following snippet cause an error of "failed: [kibana] => {"failed":
    true, "item": "", "rc": 257}
    msg: Destination
    {{kibana_doc_root}}/{{kibana_version}}/{{kibana_config_file}} does not
    exist !"

    ----------------- Snippet 2 --------
    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{kibana_config_file}}"

    - name: Replace the URI of the ElasticSearch service in config.js on
    Kibana server
    lineinfile:
    dest="{{ kibana_doc_root }}/{{ kibana_version
    }}/{{kibana_config_file}}"
    regexp="(elasticsearch.* \"http.*)$"
    state=present
    line="elasticsearch':' \" {{ elasticsearch_URL }}:{{
    elasticsearch_port }} \" "
    --------------------------------


    --
    You received this message because you are subscribed to the Google Groups
    "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/c05b0e63-ea8c-4e17-8f13-2968b068ec81%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/c05b0e63-ea8c-4e17-8f13-2968b068ec81%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgzya292YaZpwtHZMv6%2B5-2g2O5Gy%2BWW_Ks263oVHVJQpw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Sean at Jul 21, 2014 at 11:22 pm

    On Monday, July 21, 2014 4:13:17 PM UTC-7, Michael DeHaan wrote:
    A quick question or to -- what version of Ansible are you trying this on?
    ansible 1.5.4


    In your ansible.cfg, is this perhaps an upgrade that does not have "fail
    on undefined variables" turned on?
    The my ansible.cfg file within my project has one line like this:

    error_on_undefined_vars = False
    Should I change it to True?

    Most people have this on now, but not all. It's the default if you don't
    have an ansible.cfg and your version is new enough.


    On Mon, Jul 21, 2014 at 2:47 PM, Sean <sean.bi...@gmail.com <javascript:>>
    wrote:
    I tried to change one line in a file with lineinfile command, but it
    looks like this command does not resolve variables. See my playbook snippet
    below

    #in my playbook, {{ kibana_doc_root }}, {{ kibana_version }},
    {{kibana_config_file}}, {{elasticsearch_URL}}, {{ elasticsearch_port }}
    have been defined

    The following snippet can successfully change the file content in
    config.js, but {{elasticsearch_URL}} is not resolved (i.e. the line shows
    {{elasticsearch_URL}} as is):

    ----- Snippet 1 -------------
    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{kibana_config_file}}"

    - name: Replace the URI of the ElasticSearch service in config.js on
    Kibana server
    lineinfile:
    dest=/var/www/kibana/kibana-3.0.0milestone4/config.js
    regexp="(elasticsearch.* \"http.*)$"
    state=present
    line="elasticsearch':' \" {{ elasticsearch_URL }}:{{
    elasticsearch_port }} \" "
    --------------------






    The following snippet cause an error of "failed: [kibana] => {"failed":
    true, "item": "", "rc": 257}
    msg: Destination
    {{kibana_doc_root}}/{{kibana_version}}/{{kibana_config_file}} does not
    exist !"

    ----------------- Snippet 2 --------
    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{kibana_config_file}}"

    - name: Replace the URI of the ElasticSearch service in config.js on
    Kibana server
    lineinfile:
    dest="{{ kibana_doc_root }}/{{ kibana_version
    }}/{{kibana_config_file}}"
    regexp="(elasticsearch.* \"http.*)$"
    state=present
    line="elasticsearch':' \" {{ elasticsearch_URL }}:{{
    elasticsearch_port }} \" "
    --------------------------------


    --
    You received this message because you are subscribed to the Google Groups
    "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to ansible-proje...@googlegroups.com <javascript:>.
    To post to this group, send email to ansible...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/c05b0e63-ea8c-4e17-8f13-2968b068ec81%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/c05b0e63-ea8c-4e17-8f13-2968b068ec81%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3464054c-a792-4822-8e0d-6e2cf34aaf77%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Sean at Jul 21, 2014 at 11:26 pm

    On Monday, July 21, 2014 4:13:17 PM UTC-7, Michael DeHaan wrote:
    A quick question or to -- what version of Ansible are you trying this on?

    In your ansible.cfg, is this perhaps an upgrade that does not have "fail
    on undefined variables" turned on?

    Most people have this on now, but not all. It's the default if you don't
    have an ansible.cfg and your version is new enough.

    BTW, I have tested that the variables have been defined.
    Here is my playbook:

    - name: debug variables
       debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{ kibana_config_file }}"


    Here is the corresponding output:

    TASK: [kibana | debug variables]
    **********************************************

    ok: [kibana] => {

         "item": "",

         "msg": " variable concatication =
    /var/www/kibana/kibana-3.0.0milestone4/config.js"

    }

    On Mon, Jul 21, 2014 at 2:47 PM, Sean <sean.bi...@gmail.com <javascript:>>
    wrote:
    I tried to change one line in a file with lineinfile command, but it
    looks like this command does not resolve variables. See my playbook snippet
    below

    #in my playbook, {{ kibana_doc_root }}, {{ kibana_version }},
    {{kibana_config_file}}, {{elasticsearch_URL}}, {{ elasticsearch_port }}
    have been defined

    The following snippet can successfully change the file content in
    config.js, but {{elasticsearch_URL}} is not resolved (i.e. the line shows
    {{elasticsearch_URL}} as is):

    ----- Snippet 1 -------------
    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{kibana_config_file}}"

    - name: Replace the URI of the ElasticSearch service in config.js on
    Kibana server
    lineinfile:
    dest=/var/www/kibana/kibana-3.0.0milestone4/config.js
    regexp="(elasticsearch.* \"http.*)$"
    state=present
    line="elasticsearch':' \" {{ elasticsearch_URL }}:{{
    elasticsearch_port }} \" "
    --------------------






    The following snippet cause an error of "failed: [kibana] => {"failed":
    true, "item": "", "rc": 257}
    msg: Destination
    {{kibana_doc_root}}/{{kibana_version}}/{{kibana_config_file}} does not
    exist !"

    ----------------- Snippet 2 --------
    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{kibana_config_file}}"

    - name: Replace the URI of the ElasticSearch service in config.js on
    Kibana server
    lineinfile:
    dest="{{ kibana_doc_root }}/{{ kibana_version
    }}/{{kibana_config_file}}"
    regexp="(elasticsearch.* \"http.*)$"
    state=present
    line="elasticsearch':' \" {{ elasticsearch_URL }}:{{
    elasticsearch_port }} \" "
    --------------------------------


    --
    You received this message because you are subscribed to the Google Groups
    "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to ansible-proje...@googlegroups.com <javascript:>.
    To post to this group, send email to ansible...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/c05b0e63-ea8c-4e17-8f13-2968b068ec81%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/c05b0e63-ea8c-4e17-8f13-2968b068ec81%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d16012ba-c4d3-43ac-a376-a2707d4329d2%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Sean at Jul 22, 2014 at 1:08 am
    Hi all,

    Just FYI in case that other folks may find this helpful later.

    I took Michael's hint, and changed the error_on_undefined_vars from False
    to True, which basically returns an explicit error if there exists a
    missing variable, as follow.

    myproject_foler/.ansible.cfg

         #error_on_undefined_vars = False

         error_on_undefined_vars = True
    And I found that the original error was caused by one missing variable in
    the lineinfile command, {{ elasticsearch_URL }}. Once I add those variables
    in my vars file, everything start working :-)

    In short, lineinfile does take varaiables and it works perfectly

    My only slight complaint is that the error message was not as related to
    the root cause as it could be.

    Thanks to Michael.



    On Monday, July 21, 2014 4:26:19 PM UTC-7, Sean wrote:




    On Monday, July 21, 2014 4:13:17 PM UTC-7, Michael DeHaan wrote:

    A quick question or to -- what version of Ansible are you trying this on?

    In your ansible.cfg, is this perhaps an upgrade that does not have "fail
    on undefined variables" turned on?

    Most people have this on now, but not all. It's the default if you
    don't have an ansible.cfg and your version is new enough.

    BTW, I have tested that the variables have been defined.
    Here is my playbook:

    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{ kibana_config_file }}"


    Here is the corresponding output:

    TASK: [kibana | debug variables]
    **********************************************

    ok: [kibana] => {

    "item": "",

    "msg": " variable concatication =
    /var/www/kibana/kibana-3.0.0milestone4/config.js"

    }

    On Mon, Jul 21, 2014 at 2:47 PM, Sean wrote:

    I tried to change one line in a file with lineinfile command, but it
    looks like this command does not resolve variables. See my playbook snippet
    below

    #in my playbook, {{ kibana_doc_root }}, {{ kibana_version }},
    {{kibana_config_file}}, {{elasticsearch_URL}}, {{ elasticsearch_port }}
    have been defined

    The following snippet can successfully change the file content in
    config.js, but {{elasticsearch_URL}} is not resolved (i.e. the line shows
    {{elasticsearch_URL}} as is):

    ----- Snippet 1 -------------
    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{kibana_config_file}}"

    - name: Replace the URI of the ElasticSearch service in config.js on
    Kibana server
    lineinfile:
    dest=/var/www/kibana/kibana-3.0.0milestone4/config.js
    regexp="(elasticsearch.* \"http.*)$"
    state=present
    line="elasticsearch':' \" {{ elasticsearch_URL }}:{{
    elasticsearch_port }} \" "
    --------------------






    The following snippet cause an error of "failed: [kibana] => {"failed":
    true, "item": "", "rc": 257}
    msg: Destination
    {{kibana_doc_root}}/{{kibana_version}}/{{kibana_config_file}} does not
    exist !"

    ----------------- Snippet 2 --------
    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{kibana_config_file}}"

    - name: Replace the URI of the ElasticSearch service in config.js on
    Kibana server
    lineinfile:
    dest="{{ kibana_doc_root }}/{{ kibana_version
    }}/{{kibana_config_file}}"
    regexp="(elasticsearch.* \"http.*)$"
    state=present
    line="elasticsearch':' \" {{ elasticsearch_URL }}:{{
    elasticsearch_port }} \" "
    --------------------------------


    --
    You received this message because you are subscribed to the Google
    Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to ansible-proje...@googlegroups.com.
    To post to this group, send email to ansible...@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/c05b0e63-ea8c-4e17-8f13-2968b068ec81%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/c05b0e63-ea8c-4e17-8f13-2968b068ec81%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c27f4add-5bde-4f4e-9d4d-ca0013631dc9%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael DeHaan at Jul 22, 2014 at 12:07 pm
    Good deal!

    BTW, please don't run 1.5.4.

    The current ansible is 1.6.7, and contains security fixes which you should
    apply.

    On Mon, Jul 21, 2014 at 9:08 PM, Sean wrote:

    Hi all,

    Just FYI in case that other folks may find this helpful later.

    I took Michael's hint, and changed the error_on_undefined_vars from False
    to True, which basically returns an explicit error if there exists a
    missing variable, as follow.

    myproject_foler/.ansible.cfg

    #error_on_undefined_vars = False

    error_on_undefined_vars = True
    And I found that the original error was caused by one missing variable in
    the lineinfile command, {{ elasticsearch_URL }}. Once I add those variables
    in my vars file, everything start working :-)

    In short, lineinfile does take varaiables and it works perfectly

    My only slight complaint is that the error message was not as related to
    the root cause as it could be.

    Thanks to Michael.



    On Monday, July 21, 2014 4:26:19 PM UTC-7, Sean wrote:




    On Monday, July 21, 2014 4:13:17 PM UTC-7, Michael DeHaan wrote:

    A quick question or to -- what version of Ansible are you trying this on?

    In your ansible.cfg, is this perhaps an upgrade that does not have "fail
    on undefined variables" turned on?

    Most people have this on now, but not all. It's the default if you
    don't have an ansible.cfg and your version is new enough.

    BTW, I have tested that the variables have been defined.
    Here is my playbook:

    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{ kibana_config_file }}"


    Here is the corresponding output:

    TASK: [kibana | debug variables] ******************************
    ****************

    ok: [kibana] => {

    "item": "",

    "msg": " variable concatication = /var/www/kibana/kibana-3.0.
    0milestone4/config.js"

    }

    On Mon, Jul 21, 2014 at 2:47 PM, Sean wrote:

    I tried to change one line in a file with lineinfile command, but it
    looks like this command does not resolve variables. See my playbook snippet
    below

    #in my playbook, {{ kibana_doc_root }}, {{ kibana_version }},
    {{kibana_config_file}}, {{elasticsearch_URL}}, {{ elasticsearch_port }}
    have been defined

    The following snippet can successfully change the file content in
    config.js, but {{elasticsearch_URL}} is not resolved (i.e. the line shows
    {{elasticsearch_URL}} as is):

    ----- Snippet 1 -------------
    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{kibana_config_file}}"

    - name: Replace the URI of the ElasticSearch service in config.js on
    Kibana server
    lineinfile:
    dest=/var/www/kibana/kibana-3.0.0milestone4/config.js
    regexp="(elasticsearch.* \"http.*)$"
    state=present
    line="elasticsearch':' \" {{ elasticsearch_URL }}:{{
    elasticsearch_port }} \" "
    --------------------






    The following snippet cause an error of "failed: [kibana] =>
    {"failed": true, "item": "", "rc": 257}
    msg: Destination {{kibana_doc_root}}/{{kibana_
    version}}/{{kibana_config_file}} does not exist !"

    ----------------- Snippet 2 --------
    - name: debug variables
    debug: msg=" variable concatication = {{ kibana_doc_root }}/{{
    kibana_version }}/{{kibana_config_file}}"

    - name: Replace the URI of the ElasticSearch service in config.js on
    Kibana server
    lineinfile:
    dest="{{ kibana_doc_root }}/{{ kibana_version
    }}/{{kibana_config_file}}"
    regexp="(elasticsearch.* \"http.*)$"
    state=present
    line="elasticsearch':' \" {{ elasticsearch_URL }}:{{
    elasticsearch_port }} \" "
    --------------------------------


    --
    You received this message because you are subscribed to the Google
    Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to ansible-proje...@googlegroups.com.
    To post to this group, send email to ansible...@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/
    msgid/ansible-project/c05b0e63-ea8c-4e17-8f13-
    2968b068ec81%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/c05b0e63-ea8c-4e17-8f13-2968b068ec81%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups
    "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/c27f4add-5bde-4f4e-9d4d-ca0013631dc9%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/c27f4add-5bde-4f4e-9d4d-ca0013631dc9%40googlegroups.com?utm_medium=email&utm_source=footer>
    .

    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgwfrKL6FxLk5_pdaLJEvP20UY2LgZxR2TT-_gKytiwuEg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupansible-project @
postedJul 21, '14 at 6:47p
activeJul 22, '14 at 12:07p
posts6
users2

2 users in discussion

Sean: 4 posts Michael DeHaan: 2 posts

People

Translate

site design / logo © 2022 Grokbase