I'm working on an ansible role and instead of putting all tasks in tasks/main.yml, I'd like to have separate files and use them sort of like functions. One of my files has all the possible tasks for file manipulation in a separate file. The thought would be to use tags to execute one of the tasks in that file.
In the example below I've put all the file manipulation tasks in a file called 'reboot_me_file.yml and would like to call just one task in main.yml when I need it. For example, 'reboot_me_file.yml' has three tagged tasks (create a file, stat a file, delete a file) and during the main.yml play, there will be a task, that includes say the 'create a file' task. I've looked at the following URL and it sounds like I can call a tagged task in the 'reboot_me_file.yml', but when I run the playbook, it executes all the tasks in 'reboot_me_file.yml' https://docs.ansible.com/ansible/latest/modules/include_tasks_module.html#include-tasks-module (It says this should be available in ansible 2.7 but not which version of 2.7) Anyone tried anything like this? -- ansible version: ansible 2.7.10 *-- tasks/main.yml* - name: Checking for an old 'reboot_me' file include_tasks: file: reboot_me_file.yml apply: tags: - check_reboot_file *-- tasks/reboot_me_file.yml* --- # file operations on /tmp/reboot_me.txt - name: Creating the file 'reboot_me' file: path: "/tmp/reboot_me" state: touch mode: 0666 tags: - create_reboot_file - name: Checking for the file 'reboot_me' stat: path: /tmp/reboot_me register: file_reboot_me tags: - check_reboot_file - name: Removing the file 'reboot_me' file: path: "/tmp/reboot_me" state: absent tags: - remove_reboot_file -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/173c9748-8b20-49fd-adbf-3ca351d7d90f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
