include_playbook.yml его будем уменьшать и использовать include / import
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
--- - name: My TEST Playbook hosts: all become: yes vars: mytext: "Privet MEN" tasks: - name: Ping test ping: - name: Create folder1 file: path: /home/secret/folder1 state: directory mode: 0755 - name: Create folder2 file: path: /home/secret/folder2 state: directory mode: 0755 - name: Create file1 copy: dest: /home/secret/file1.txt content: Text Line1, in file1 Text Line2, in file1 Text Line3, {{ mytext }} - name: Create file2 copy: dest: /home/secret/file2.txt content: Text Line1, in file2 Text Line2, in file2 Text Line3, {{ mytext }} ... |
create_folder.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
--- - name: Create folder1 file: path: /home/secret/folder1 state: directory mode: 0755 - name: Create folder2 file: path: /home/secret/folder2 state: directory mode: 0755 ... |
create_files.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
--- - name: Create file1 copy: dest: /home/secret/file1.txt content: | Text Line1, in file1 Text Line2, in file1 Text Line3, {{ mytext }} - name: Create file2 copy: dest: /home/secret/file2.txt content: | Text Line1, in file2 Text Line2, in file2 Text Line3, {{ mytext }} ... |
include_playbook.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
--- - name: My TEST Playbook hosts: all become: yes vars: mytext: "Privet MEN" tasks: - name: Ping test ping: - name: Create Folders include: create_folder.yml - name: Create Files import: create_files.yml ... !!! Отличие import от include заключается в следующем !!! Include читает из файлов значения, ansible подставляет значения при выполнении (дошел до строчки с include тогда и подставил) !!! Import читает и подставляет значения, ansible подставляет сразу все значения !!! рекомендуют использовать include !!! Также можно сократить запись --- - name: My TEST Playbook hosts: all become: yes vars: mytext: "Privet MEN" tasks: - name: Ping test ping: - include: create_folder.yml - include: create_files.yml mytext="Hello from Mosckow" ... |