Subject: [ansible-project] Create file who is in my csv file


On Mon, 13 Jan 2020 08:10:14 -0800 (PST)
Karther <[EMAIL PROTECTED]> wrote:

You might be better off with the 'read_csv' module
https://docs.ansible.com/ansible/latest/modules/read_csv_module.html#read-csv-read-a-csv-file

For example

    - hosts: localhost
      tasks:
        - read_csv:
            path: csv_file.csv
          register: my_files
        - debug:
            var: my_files.list

gives

    "my_files.list": [
        {
            "filename": "file1",
            "note": "my fisrt note",
            "state": "0",
            "temps": "52"
        },
        {
            "filename": "file2",
            "note": "my second note",
            "state": "0",
            "temps": "34"
        },
        {
            "filename": "file3",
            "note": "my thirst note",
            "state": "0",
            "temps": "71"
        }
    ]

The loop the list and create files. For example

    - copy:
        dest: "{{ item.filename }}"
        content: "{{ item.note }}"
      loop: "{{ my_files.list }}"

HTH,

-vlado

--

iQEzBAEBCAAdFiEEbaThuYKQgbbmDrVkkNGZEo7UTwEFAl4cnC0ACgkQkNGZEo7U
TwEolAgAzdjAZc7tRlm2X8iklSlX1wQxbrTkU2VKdihO4vuqB5rF/MBvghwkpQTc
X1L7W1Z4vmVjn5w6QvB75KkpOrqpMNPtRN/M7OuIgcrXWAVanqWzGZzfCbZTzTyX
kMRRBLqICKid66EmblLgDJwfZaGdr0DgFAZ8M0IdCTHgx2uZGc7cmMmglefPqipF
pzKOKd9T5kRvo4GgkLVsvr//UsFDEVSEaoYtuch+Q77NBxo6F3NrFMc9jZPtX6hm
n4ESJQaANPLRUy0EmKeuxmMmRysuU4mWs4cHzUBBu5ZHvjsHLJL4R3XoYyN2mnFJ
pLc6MolWb/TT1zHsVKRNwIB6phAJbw==
=odL0
-----END PGP SIGNATURE-----