name: start Apache service: name=apache2 state=started enabled=yes Task can call a module and may have a parameters. There are a lot of modules and you can write your own.
- name: create db command: /usr/bin/create_database.sh arg1 arg2 creates=/path/to/database The command will be executed on all selected nodes. It will not processed through the shell, so environment variables and operator like "<", ">", "|", and “&" will not work. It’s more securely and predictably. Best practice suggest command. - shell: somescript.sh > somelog.txt args: chdir: somedir/ #cd into this directory before running the command creates: somelog.txt Runs the command through a shell (/bin/sh) on the remote node
mode=644 backup=yes Copy “site.it.conf” file in selected nodes, backing up the original if it differs from the copied version - name: Copy my.cnf global MySQL configuration. template: > src=my.cnf.j2 dest=/etc/my.cnf owner=root group=root mode=644 notify: restart mysql Template are processed by Jinja2 and copied on dest source. Note that “src” can be relative or absolute path (if you use roles is the template folder path).
a variable to access it later. tasks: - command: /bin/false register: result - command: /bin/something when: result|failed … The resulting variables can be used in templates, action tasks, or when statements.
useful for debugging variables or expressions without necessarily halting the playbook. - debug: msg="System {{ inventory_hostname }} has uuid {{ ansible_product_uuid }}” - shell: /usr/bin/uptime register: result - debug: var=result