Hi all Could someone lend me a hand to figure looping over variables?
I've got a number of hosts which are grouped in the inventory quite strictly in a rather traditional way: dev-group1 hostA hostB tst-group1 hostC hostD pre-group1 hostE hostF pro-group1 hostG hostH dev-group2 hostI hostJ tst-group2 hostK hostL and so on... I'm about to replace/template a great number of files in them and I'd like to have local backups first ;) The only requirement is that the files have to be fetched to an already established structure that mimics the inventory: /backup/dev-group1/ /backup/tst-group1/ etc... So I made an attempt to loop over each group: $ ansible-playbook fetch_from_server.yml -sK --extra-vars "@fetch_loop_vars.yml" -v fetch_loop_vars.yml looks like this: --- file: '/root/.bash_profile' my_groups: ['0dm-sap', 'dev-sap', 'tst-sap', 'pre-sap', 'pro-sap'] And my fetch_from_server.yml is this: --- - hosts: '{{my_groups}}' sudo: True gather_facts: no tasks: - name: fetch the file from the server fetch: src={{file}} dest=/backup/{{my_groups}}/{{inventory_hostname}} I get this result when running: ok: [hostA] => {"changed": false, "dest": "/backup/*[dev-group1,/hostA/* root/.bash_profile", "file": "/root/.bash_profile", "md5sum": "bab9333347e752b87add49020919a078"} ok: [hostB] => {"changed": false, "dest": "/backup/*[dev-group1,/hostB/* root/.bash_profile", "file": "/root/.bash_profile", "md5sum": "bab9333347e752b87add49020919a078"} ok: [hostD] => {"changed": false, "dest": "/backup/*[dev-group1,/hostC/* root/.bash_profile", "file": "/root/.bash_profile", "md5sum": "bab9333347e752b87add49020919a078"} ok: [hostC] => {"changed": false, "dest": "/backup/*[dev-group1,/hostD/* root/.bash_profile", "file": "/root/.bash_profile", "md5sum": "bab9333347e752b87add49020919a078"} And I'd like to get: ok: [hostA] => {"changed": false, "dest": "/backup/*dev-group1/hostA* /root/.bash_profile", "file": "/root/.bash_profile", "md5sum": "bab9333347e752b87add49020919a078"} ok: [hostB] => {"changed": false, "dest": "/backup/*dev-group1/hostB* /root/.bash_profile", "file": "/root/.bash_profile", "md5sum": "bab9333347e752b87add49020919a078"} ok: [hostD] => {"changed": false, "dest": "/backup/*tst-group1/hostC* /root/.bash_profile", "file": "/root/.bash_profile", "md5sum": "bab9333347e752b87add49020919a078"} ok: [hostC] => {"changed": false, "dest": "/backup/*tst-group1/hostD* /root/.bash_profile", "file": "/root/.bash_profile", "md5sum": "bab9333347e752b87add49020919a078"} So the problems are: - It's not iterating over {{my_groups}}. Every host is placed under the first defined group: dev-group1 - It's actually writing the dir of the group as "[dev-group1," which of course is not what I need. I'm sure this is a trivial issue for those fluent in python, which obviously is not my case. Any help appreciated Thanks! -- 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/f6d66901-d9c3-46b6-9738-7ef472a7674d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.