FAQ
Apologies for what may be a silly question.

Within a role, I'd like to run a verification command on some files from the
.../files/ directory before installing them. I can see how to use a
'local_action' and the command or shell module for this. But I can't see how to
give the verification command an appropriate path to the file to process. The
best I can come up with is a solution based on playbook_dir:

    {{ playbook_dir }}/roles/foobar-config/files/{{ item }}

But this is brittle, because it includes the role name which might change. Is
there a better way to do this?

Jon.

--
Jon Warbrick
Information Systems Manager, University of Cambridge Information Services

--
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/alpine.DEB.2.02.1407011644490.22659%40mnementh.csi.cam.ac.uk.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Michael DeHaan at Jul 1, 2014 at 6:51 pm
    This is what we have right now, there isn't a role variable that says
    what's the path of the current role, because of the way roles are expanded,
    can have dependencies, and so on.

    I don't suspect your role name will change any, so it shouldn't be much of
    a problem - if it does, the validation step would fail, which is a good
    reason to test playbooks anyway.

    See http://docs.ansible.com/test_strategies.html for some notes about stage
    environments for example

    On Tue, Jul 1, 2014 at 11:45 AM, Jon Warbrick wrote:

    Apologies for what may be a silly question.

    Within a role, I'd like to run a verification command on some files from
    the .../files/ directory before installing them. I can see how to use a
    'local_action' and the command or shell module for this. But I can't see
    how to give the verification command an appropriate path to the file to
    process. The best I can come up with is a solution based on playbook_dir:

    {{ playbook_dir }}/roles/foobar-config/files/{{ item }}

    But this is brittle, because it includes the role name which might change.
    Is there a better way to do this?

    Jon.

    --
    Jon Warbrick
    Information Systems Manager, University of Cambridge Information Services

    --
    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/alpine.DEB.2.02.1407011644490.22659%
    40mnementh.csi.cam.ac.uk.
    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%2BnsWgyc6GXvb%2B0g1_L7QrWxCrh5Q-EvJRzQDwPb%2BNEVF9Bg1A%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jon Warbrick at Jul 12, 2014 at 12:38 pm

    On Tue, 1 Jul 2014, Michael DeHaan wrote:

    This is what we have right now, there isn't a role variable that says
    what's the path of the current role, because of the way roles are expanded,
    can have dependencies, and so on.

    I don't suspect your role name will change any, so it shouldn't be much of
    a problem - if it does, the validation step would fail, which is a good
    reason to test playbooks anyway.
    Belated thanks for that - I'll stick with my current approach, though I'm
    now wondering if role dependencies, etc, may mean even that won't always
    work.

    Jon.

    --
    Jon Warbrick
    Information Systems Manager, University of Cambridge Information Services

    --
    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/alpine.OSX.2.00.1407121336400.1232%40ramoth.brsn.invalid.
    For more options, visit https://groups.google.com/d/optout.
  • Mikhail Koshelev at Jul 1, 2014 at 8:56 pm
    Hi Jon,

    There's actually a way (hack?) to get role directory by using lookup.
    Define 'role_dir' var as shown below and you can use it in your roles'
    tasks files to refer to the current role directory:
    role_dir: "{{ lookup('pipe','pwd')|dirname }}"

    Just note, this works as long as the tasks file (or included fragment)
    using 'role_dir' variable is located in the role's 'tasks' dir. Doesn't
    work if used in the fragment included from outside.

    Also, role name can be obtained in the same way:
    role_name: "{{ lookup('pipe','pwd')|dirname|basename }}"

    On Tuesday, July 1, 2014 11:37:18 AM UTC-7, Jon Warbrick wrote:

    Apologies for what may be a silly question.

    Within a role, I'd like to run a verification command on some files from
    the
    .../files/ directory before installing them. I can see how to use a
    'local_action' and the command or shell module for this. But I can't see
    how to
    give the verification command an appropriate path to the file to process.
    The
    best I can come up with is a solution based on playbook_dir:

    {{ playbook_dir }}/roles/foobar-config/files/{{ item }}

    But this is brittle, because it includes the role name which might change.
    Is
    there a better way to do this?

    Jon.

    --
    Jon Warbrick
    Information Systems Manager, University of Cambridge Information Services
    --
    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/9d28c301-71d8-445a-9242-932f635227f2%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael DeHaan at Jul 1, 2014 at 10:12 pm
    Just note that if you have --forks 200 that "pwd" will get executed 200
    times at once, which might make your system unhappy.



    On Tue, Jul 1, 2014 at 4:56 PM, Mikhail Koshelev wrote:

    Hi Jon,

    There's actually a way (hack?) to get role directory by using lookup.
    Define 'role_dir' var as shown below and you can use it in your roles'
    tasks files to refer to the current role directory:
    role_dir: "{{ lookup('pipe','pwd')|dirname }}"

    Just note, this works as long as the tasks file (or included fragment)
    using 'role_dir' variable is located in the role's 'tasks' dir. Doesn't
    work if used in the fragment included from outside.

    Also, role name can be obtained in the same way:
    role_name: "{{ lookup('pipe','pwd')|dirname|basename }}"

    On Tuesday, July 1, 2014 11:37:18 AM UTC-7, Jon Warbrick wrote:

    Apologies for what may be a silly question.

    Within a role, I'd like to run a verification command on some files from
    the
    .../files/ directory before installing them. I can see how to use a
    'local_action' and the command or shell module for this. But I can't see
    how to
    give the verification command an appropriate path to the file to process.
    The
    best I can come up with is a solution based on playbook_dir:

    {{ playbook_dir }}/roles/foobar-config/files/{{ item }}

    But this is brittle, because it includes the role name which might
    change. Is
    there a better way to do this?

    Jon.

    --
    Jon Warbrick
    Information Systems Manager, University of Cambridge Information Services
    --
    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/9d28c301-71d8-445a-9242-932f635227f2%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/9d28c301-71d8-445a-9242-932f635227f2%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%2BnsWgzdLM0iSswvipAsTchH4ummTyL76-S4sNxQBPi9KnCiuw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jon Warbrick at Jul 12, 2014 at 12:49 pm

    On Tue, 1 Jul 2014, Mikhail Koshelev wrote:

    There's actually a way (hack?) to get role directory by using lookup.
    Define 'role_dir' var as shown below and you can use it in your roles'
    tasks files to refer to the current role directory:
    role_dir: "{{ lookup('pipe','pwd')|dirname }}"
    So this assumes that, when the role_dir variable is expanded, the current
    directory will be one inside the relevant role directory? That's not what
    I thought I saw, but perhaps I was wrong.

    But if that *is* the case, surely I could use relative paths to construct
    paths to any other files in the role and bypass the need to run 'pwd'?

    I fear I'm missing something...

    Jon.

    --
    Jon Warbrick
    Information Systems Manager, University of Cambridge Information Services

    --
    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/alpine.OSX.2.00.1407121338330.1232%40ramoth.brsn.invalid.
    For more options, visit https://groups.google.com/d/optout.
  • Michael DeHaan at Jul 12, 2014 at 12:54 pm
    "So this assumes that, when the role_dir variable is expanded, the current
    directory will be one inside the relevant role directory? That's not what I
    thought I saw, but perhaps I was wrong."

    Might be helpful to share what you saw, showing both the actual vs expected
    values, and playbook snippets.

    I'm not sure I understand the pwd issue but yes "/../" and the like do work
    in Ansible.



    On Sat, Jul 12, 2014 at 8:49 AM, Jon Warbrick wrote:

    On Tue, 1 Jul 2014, Mikhail Koshelev wrote:

    There's actually a way (hack?) to get role directory by using lookup.
    Define 'role_dir' var as shown below and you can use it in your roles'
    tasks files to refer to the current role directory:
    role_dir: "{{ lookup('pipe','pwd')|dirname }}"
    So this assumes that, when the role_dir variable is expanded, the current
    directory will be one inside the relevant role directory? That's not what I
    thought I saw, but perhaps I was wrong.

    But if that *is* the case, surely I could use relative paths to construct
    paths to any other files in the role and bypass the need to run 'pwd'?

    I fear I'm missing something...


    Jon.

    --
    Jon Warbrick
    Information Systems Manager, University of Cambridge Information Services

    --
    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/alpine.OSX.2.00.1407121338330.1232%
    40ramoth.brsn.invalid.

    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%2BnsWgxFhathtNK4t3%3DRpmuOaKMoqL-5eq8ahRVLdbtEJeZtGQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupansible-project @
postedJul 1, '14 at 6:37p
activeJul 12, '14 at 12:54p
posts7
users3

People

Translate

site design / logo © 2022 Grokbase