Ansible: Difference between revisions
Jump to navigation
Jump to search
(→debug) |
(→date) |
||
Line 25: | Line 25: | ||
msg: "{{ vm_data }}" | msg: "{{ vm_data }}" | ||
=date= | =date= | ||
<pre> | |||
Test to get dates with wanted format. test.yml # ansible-playbook test.yml | Test to get dates with wanted format. test.yml # ansible-playbook test.yml | ||
- hosts: localhost | - hosts: localhost | ||
Line 33: | Line 34: | ||
- debug: msg="the current date is {{ ansible_date_time.date }}_{{ ansible_date_time.hour }}-{{ ansible_date_time.minute }}" | - debug: msg="the current date is {{ ansible_date_time.date }}_{{ ansible_date_time.hour }}-{{ ansible_date_time.minute }}" | ||
- debug: msg="{{ date_hour_minute }}" | - debug: msg="{{ date_hour_minute }}" | ||
</pre> |
Revision as of 05:54, 21 September 2021
ansible options
-l SUBSET, --limit SUBSET (further limit selected hosts to an additional pattern) -t TAGS, --tags TAGS (only run plays and tasks tagged with these values) -e EXTRA_VARS, --extra-vars EXTRA_VARS (set additional variables as key=value or YAML/JSON, if filename prepend with @)
dont fail on errors
ignore_errors: yes
Start where you left off
ansible-playbook playbook.yml --start-at-task="install packages"
adhoc command
ansible remote.host -u ${USER}_sysadmin -a id
debug
- name: debug1 debug: var: filesystem - name: debug2 debug: msg: "Template:Item.mount" loop: "Template:Ansible mounts"
Print a register
- name: Print return information from the previous task debug: msg: "Template:Vm data"
date
Test to get dates with wanted format. test.yml # ansible-playbook test.yml - hosts: localhost vars: # date_hour_minute: "{{ ansible_date_time.date }}_{{ ansible_date_time.hour }}-{{ ansible_date_time.minute }}" date_hour_minute: "{{ lookup('pipe','date +%Y-%m-%d_%H-%M-%S') }}" tasks: - debug: msg="the current date is {{ ansible_date_time.date }}_{{ ansible_date_time.hour }}-{{ ansible_date_time.minute }}" - debug: msg="{{ date_hour_minute }}"