[ansible-project] How to force Ansible to update PATH?
I am installing snapd via Ansible on *buntu. After installation, snap binaries are linked from `/snap/bin`. When snapd is installed, it adds a script to `/etc/profile.d/` that basically add /snap/bin to bash PATH. My problem is that I cannot find a way to force Ansible to refresh the path, so subsequent roles/tasks fail with " command not found in PATH" I have tried: 1. Ansible `meta: reset_connection` task -- fails with message "unable to reset this type of connection" (local) 2. In playbook: `environment: PATH: '/snap/bin:{{ ansible_env.PATH }}' -- no effect 3. In role: `shell: 'export PATH=$PATH:/snap/bin'` -- no effect Short of forcing a reboot mid-way through a playbook, any other ideas? -- 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+unsubscr...@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/633ae612-9ef0-490c-84d0-786591bcc77a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] How to convert a dictionary to a list with key=value elements or to a string with key=value elements?
That is what I ended up doing, but was curious if there is a 'filter' way. On Saturday, October 20, 2018 at 11:01:32 AM UTC-6, Kai Stian Olstad wrote: > > On Saturday, 20 October 2018 17:59:07 CEST Dmitriy Panteleyev wrote: > > Is there a way to modify this so that the item to the right of the equal > > sign was quoted? > > > > So... one="wan", two="too", three="tree" > > You can always use Jinja template > > - debug: msg="{% for k, v in test.iteritems() %}{{ k }}="{{ v }}"{% if > not loop.last %}, {% endif %}{% endfor %}" > > -- > Kai Stian Olstad > > > -- 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+unsubscr...@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/eb879aeb-ef35-4bad-8165-98aebae764de%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] How to convert a dictionary to a list with key=value elements or to a string with key=value elements?
Is there a way to modify this so that the item to the right of the equal sign was quoted? So... one="wan", two="too", three="tree" On Friday, October 19, 2018 at 2:06:01 PM UTC-6, Dmitriy Panteleyev wrote: > > I'll give that a try, thank you. > > > On Friday, October 19, 2018 at 12:04:27 PM UTC-6, Matt Martz wrote: >> >> This should do the trick: >> >> {{ test|dictsort|map('join', '=')|join(', ') }} >> >> In my test, it produces: >> >> ok: [localhost] => { >> "msg": "one=wan, three=tree, two=too" >> } >> >> It's ordered slightly different than your version, and dictsort could >> help change the sort order, however just a note that python dictionaries in >> most python versions are unsorted. >> >> On Fri, Oct 19, 2018 at 12:55 PM Dmitriy Panteleyev >> wrote: >> >>> Given an *arbitrary* dictionary like: >>> >>> test: >>> one: wan >>> two: too >>> three: tree >>> >>> How can I convert it to a list like: >>> >>> test: >>> - one=wan >>> - two=too >>> - thee=tree >>> >>> The end result that I need is actually a string of these list items >>> ("one=one, two=too, three=tree"). I know that I can easily `join()` a list >>> of items, but if there is an easier way to directly convert the dictionary >>> to a string, that would work too. >>> >>> Again, I know neither the number of dictionary elements, nor the key >>> names. >>> >>> A solution that works in version 2.5 would be best... >>> >>> -- >>> 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/ad406797-d8bb-4735-bce4-41c9b71a2388%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/ansible-project/ad406797-d8bb-4735-bce4-41c9b71a2388%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> -- >> Matt Martz >> @sivel >> sivel.net >> > -- 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+unsubscr...@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/b8d4b422-9f09-40e5-9802-da587912f62c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] How to convert a dictionary to a list with key=value elements or to a string with key=value elements?
I'll give that a try, thank you. On Friday, October 19, 2018 at 12:04:27 PM UTC-6, Matt Martz wrote: > > This should do the trick: > > {{ test|dictsort|map('join', '=')|join(', ') }} > > In my test, it produces: > > ok: [localhost] => { > "msg": "one=wan, three=tree, two=too" > } > > It's ordered slightly different than your version, and dictsort could help > change the sort order, however just a note that python dictionaries in most > python versions are unsorted. > > On Fri, Oct 19, 2018 at 12:55 PM Dmitriy Panteleyev > wrote: > >> Given an *arbitrary* dictionary like: >> >> test: >> one: wan >> two: too >> three: tree >> >> How can I convert it to a list like: >> >> test: >> - one=wan >> - two=too >> - thee=tree >> >> The end result that I need is actually a string of these list items >> ("one=one, two=too, three=tree"). I know that I can easily `join()` a list >> of items, but if there is an easier way to directly convert the dictionary >> to a string, that would work too. >> >> Again, I know neither the number of dictionary elements, nor the key >> names. >> >> A solution that works in version 2.5 would be best... >> >> -- >> 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/ad406797-d8bb-4735-bce4-41c9b71a2388%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ansible-project/ad406797-d8bb-4735-bce4-41c9b71a2388%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Matt Martz > @sivel > sivel.net > -- 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+unsubscr...@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/ee8fdf48-cec1-4af1-b66b-2b8ee9fc27c4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] How to convert a dictionary to a list with key=value elements or to a string with key=value elements?
Given an *arbitrary* dictionary like: test: one: wan two: too three: tree How can I convert it to a list like: test: - one=wan - two=too - thee=tree The end result that I need is actually a string of these list items ("one=one, two=too, three=tree"). I know that I can easily `join()` a list of items, but if there is an easier way to directly convert the dictionary to a string, that would work too. Again, I know neither the number of dictionary elements, nor the key names. A solution that works in version 2.5 would be best... -- 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+unsubscr...@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/ad406797-d8bb-4735-bce4-41c9b71a2388%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Re: include_role with passed variable defined by template fails
Finally tracked the issue down to my misunderstanding of how lookup() works. Answer here: https://groups.google.com/forum/#!topic/ansible-project/McPi-i-90yU On Monday, October 15, 2018 at 10:06:00 PM UTC-6, Dmitriy Panteleyev wrote: > > I'm a bit confused how variables are defined when using `include_role`. A > basic example follows. > > */play.yml* > - hosts: localhost > roles: > - one > > > > */roles/one/tasks/main.yml* > --- > - name: do a thing with another role > include_role: > name: two > vars: >passed_variable: > - stuff: "{{ lookup('template', 'role_one_template.j2') }}" > > > */roles/one/templates/role_one_template_file.j2* > bla bla bla bla > random bit of stuff > does not matter what > > > */roles/two/tasks/main.yml* > --- > - debug: > var: passed_variable > > > My expectation is that role "one" will pull the template and pass the > *results* of that lookup to role "two". However, when running the play, > I get first a warning, and then an error. It *seems* as if the template > lookup occurs in role "two". So, what exactly is going on, and how do I > fix it? > > > looking for "role_one_template.j2" at >> "/roles/two/templates/role_one_template.j2" >> looking for "role_one_template.j2" at "/roles/two/role_one_template.j2" >> looking for "role_one_template.j2" at "/templates/role_one_template.j2" >> looking for "role_one_template.j2" at "/role_one_template.j2" >> [WARNING]: Unable to find 'role_one_template.j2' in expected paths (use >> -v to see paths) > > ... >> ... > > ERROR! An unhandled exception occurred while templating '{u'stuff': [{{ >> lookup(\'template\', \'role_one_template.j2\') }}]}'. >> Error was a , original message: An >> unhandled exception occurred while running the lookup plugin 'template'. >> Error was a , original message: the >> template file role_one_template.j2 could not be found for the lookup > > > > > -- 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+unsubscr...@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/23be716a-7355-41f3-ae95-1cbf57ae22f7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Re: When are file lookups performed? How to store lookup result in a variable?
Thank you for clearing it up! On Thursday, October 18, 2018 at 11:54:12 AM UTC-6, Dmitriy Panteleyev wrote: > > I was under the impression that if I define a variable with a `lookup` > function, it would store the results of the lookup. And then when I used > that variable, it would spit out the results of the lookup. > > However, from running a bunch of different test cases that Ansible > performs the lookup every time I try to use that variable. Is that by > design? Is there a way to avoid repeated lookups? > > > So... expectation: > > myvar: lookup(...) > > >>> look up stuff and store result of lookup in 'myvar' > > - name: '{{ myvar }}' > > >>> spit out contents of 'myvar' > > - debug: > var: myvar > > >>> spit out contents of 'myvar' > > etc. > > > > What seems to be happening is... > > myvar: lookup(...) > > >>> look up stuff > > - name: '{{ myvar }}' > > >>> look at 'myvar' and perform the lookup defined by it, then spit out > result > > - debug: > var: myvar > > >>> look at 'myvar' and perform the lookup defined by it, then spit out > result > > etc. > > -- 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+unsubscr...@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/25bfa572-884f-4b6d-b82c-5e8e66c88b57%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] When are file lookups performed? How to store lookup result in a variable?
I was under the impression that if I define a variable with a `lookup` function, it would store the results of the lookup. And then when I used that variable, it would spit out the results of the lookup. However, from running a bunch of different test cases that Ansible performs the lookup every time I try to use that variable. Is that by design? Is there a way to avoid repeated lookups? So... expectation: myvar: lookup(...) >>> look up stuff and store result of lookup in 'myvar' - name: '{{ myvar }}' >>> spit out contents of 'myvar' - debug: var: myvar >>> spit out contents of 'myvar' etc. What seems to be happening is... myvar: lookup(...) >>> look up stuff - name: '{{ myvar }}' >>> look at 'myvar' and perform the lookup defined by it, then spit out result - debug: var: myvar >>> look at 'myvar' and perform the lookup defined by it, then spit out result etc. -- 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+unsubscr...@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/cc7129b8-6011-4e1f-b8b5-19c6595a3945%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] include_role with passed variable defined by template fails
Sorry, that was just a typo in my example. The filenames all match. On Tuesday, October 16, 2018 at 8:48:22 AM UTC-6, Matt Martz wrote: > > The template does not exist. You are using the wrong template file in > your lookup call: > > ``` > - stuff: "{{ lookup('template', 'role_one_template.j2') }}" > ``` > > However, you have indicated the file is actually > named: /roles/one/templates/role_one_template_file.j2 > > On Mon, Oct 15, 2018 at 11:06 PM Dmitriy Panteleyev > wrote: > >> I'm a bit confused how variables are defined when using `include_role`. >> A basic example follows. >> >> */play.yml* >> - hosts: localhost >> roles: >> - one >> >> >> >> */roles/one/tasks/main.yml* >> --- >> - name: do a thing with another role >> include_role: >> name: two >> vars: >>passed_variable: >> - stuff: "{{ lookup('template', 'role_one_template.j2') }}" >> >> >> */roles/one/templates/role_one_template_file.j2* >> bla bla bla bla >> random bit of stuff >> does not matter what >> >> >> */roles/two/tasks/main.yml* >> --- >> - debug: >> var: passed_variable >> >> >> My expectation is that role "one" will pull the template and pass the >> *results* of that lookup to role "two". However, when running the play, >> I get first a warning, and then an error. It *seems* as if the template >> lookup occurs in role "two". So, what exactly is going on, and how do I >> fix it? >> >> >> looking for "role_one_template.j2" at >>> "/roles/two/templates/role_one_template.j2" >>> looking for "role_one_template.j2" at "/roles/two/role_one_template.j2" >>> looking for "role_one_template.j2" at "/templates/role_one_template.j2" >>> looking for "role_one_template.j2" at "/role_one_template.j2" >>> [WARNING]: Unable to find 'role_one_template.j2' in expected paths (use >>> -v to see paths) >> >> ... >>> ... >> >> ERROR! An unhandled exception occurred while templating '{u'stuff': [{{ >>> lookup(\'template\', \'role_one_template.j2\') }}]}'. >>> Error was a , original message: An >>> unhandled exception occurred while running the lookup plugin 'template'. >>> Error was a , original message: the >>> template file role_one_template.j2 could not be found for the lookup >> >> >> >> >> -- >> 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/16d95836-e93b-4e98-828d-9b4f176a0047%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ansible-project/16d95836-e93b-4e98-828d-9b4f176a0047%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Matt Martz > @sivel > sivel.net > -- 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+unsubscr...@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/caff13ff-e78a-4fd2-ba50-d48e2f7a79cc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] include_role with passed variable defined by template fails
I'm a bit confused how variables are defined when using `include_role`. A basic example follows. */play.yml* - hosts: localhost roles: - one */roles/one/tasks/main.yml* --- - name: do a thing with another role include_role: name: two vars: passed_variable: - stuff: "{{ lookup('template', 'role_one_template.j2') }}" */roles/one/templates/role_one_template_file.j2* bla bla bla bla random bit of stuff does not matter what */roles/two/tasks/main.yml* --- - debug: var: passed_variable My expectation is that role "one" will pull the template and pass the *results* of that lookup to role "two". However, when running the play, I get first a warning, and then an error. It *seems* as if the template lookup occurs in role "two". So, what exactly is going on, and how do I fix it? looking for "role_one_template.j2" at > "/roles/two/templates/role_one_template.j2" > looking for "role_one_template.j2" at "/roles/two/role_one_template.j2" > looking for "role_one_template.j2" at "/templates/role_one_template.j2" > looking for "role_one_template.j2" at "/role_one_template.j2" > [WARNING]: Unable to find 'role_one_template.j2' in expected paths (use > -v to see paths) ... > ... ERROR! An unhandled exception occurred while templating '{u'stuff': [{{ > lookup(\'template\', \'role_one_template.j2\') }}]}'. > Error was a , original message: An > unhandled exception occurred while running the lookup plugin 'template'. > Error was a , original message: the > template file role_one_template.j2 could not be found for the lookup -- 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+unsubscr...@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/16d95836-e93b-4e98-828d-9b4f176a0047%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] YAML line breaks (newlines) when performing lookups of files or templates
Thanks for the insight. Turns out the problem is in one of Ansible's modules, not the formatting of the lookup result. On Monday, October 15, 2018 at 10:10:36 AM UTC-6, Kai Stian Olstad wrote: > > On Saturday, 13 October 2018 18.37.22 CEST Dmitriy Panteleyev wrote: > > I've been banging my head against this for two days. Maybe I'm missing > > something. When fetching a YAML file or template with lookup function, > all > > the newlines are not preserved, but converted to '\n'. > > They are not converted, this is just how the default callback plugin > chooses to show the content in the debug module. > > > > This does not > > happen for other file types (like json). Is this the expected behavior? > > Yes > > > > Is there a way around it? > > Ansible is not a reporting tool, so if that is what you are looking for > you probably need some other tool. > That being said you have many callback plugins to choose[1] and if non of > them suites your need to can always create you own. > > > [1] https://docs.ansible.com/ansible/2.7/plugins/callback.html#plugin-list > > -- > Kai Stian Olstad > > > -- 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+unsubscr...@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/0a4c820b-0ac0-44a0-bc51-6181f9998cee%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] YAML line breaks (newlines) when performing lookups of files or templates
I've been banging my head against this for two days. Maybe I'm missing something. When fetching a YAML file or template with lookup function, all the newlines are not preserved, but converted to '\n'. This does not happen for other file types (like json). Is this the expected behavior? Is there a way around it? Examples follow: given file 'test.yml' json: - rigid - better for data interchange yaml: - slim and flexible - better for configuration object: key: value array: - null_value: - boolean: true - integer: 1 paragraph: > Blank lines denote paragraph breaks content: |- Or we can auto convert line breaks to save space printing out a lookup: - debug: msg: "{{ lookup('file', test.yml') }}" results in: > ok: [localhost] => { > "msg": "json:\n - rigid\n - better for data interchange\nyaml:\n - > slim and flexible\n - better for configuration\nobject:\n key: value\n > array:\n- null_value:\n- boolean: true\n- integer: > 1\nparagraph: >\n Blank lines denote\n\n paragraph breaks\ncontent: > |-\n Or we\n can auto\n convert line breaks\n to save space" > } On the other hand, given the same info in JSON ('test.json'): { "json": [ "rigid", "better for data interchange" ], "yaml": [ "slim and flexible", "better for configuration" ], "object": { "key": "value", "array": [ { "null_value": null }, { "boolean": true }, { "integer": 1 } ] }, "paragraph": "Blank lines denote\nparagraph breaks\n", "content": "Or we\ncan auto\nconvert line breaks\nto save space" } and printing out the same lookup: - debug: msg: "{{ lookup('file', test.json') }}" results in: > ok: [localhost] => { > "msg": { > "content": "Or we\ncan auto\nconvert line breaks\nto save space", > "json": [ > "rigid", > "better for data interchange" > ], > "object": { > "array": [ > { > "null_value": null > }, > { > "boolean": true > }, > { > "integer": 1 > } > ], > "key": "value" > }, > "paragraph": "Blank lines denote\nparagraph breaks\n", > "yaml": [ > "slim and flexible", > "better for configuration" > ] > } > } -- 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+unsubscr...@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/b4025b7e-c566-4113-b114-8ec0db1e01ce%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.