Difference between revisions of "Ansible print and debug examples"

From wikieduonline
Jump to navigation Jump to search
Line 1: Line 1:
<pre>
 
#!/usr/bin/env ansible-playbook
 
  
- hosts: localhost
+
#!/usr/bin/env ansible-playbook
  gather_facts: no
+
  [[vars:]]
+
- hosts: localhost
    my_var: MY_VALUE
+
  gather_facts: no
 
+
  [[vars:]]
  tasks:
+
    my_var: MY_VALUE
  - name: My first task for executing hello world
+
    command: echo test
+
  tasks:
 
+
    - name: My first task for executing hello world
  - name: My second task debug message name
+
      command: echo test
    debug:
+
      msg: "my debug text"
+
    - name: My second task debug message name
 
+
      debug:
  - name: My third task to print a text and variable
+
      msg: "my debug text"
    debug:
+
      msg: "my debug text including var {{ my_var }}"
+
    - name: My third task to print a text and variable
</pre>
+
      debug:
 +
      msg: "my debug text including var {{ my_var }}"
  
 
== Output ==
 
== Output ==

Revision as of 15:09, 11 August 2022

#!/usr/bin/env ansible-playbook

- hosts: localhost
  gather_facts: no
  vars:
    my_var: MY_VALUE

  tasks:
   - name: My first task for executing hello world
     command: echo test

   - name: My second task debug message name
     debug:
      msg: "my debug text"

   - name: My third task to print a text and variable
     debug:
      msg: "my debug text including var Template:My var"

Output


PLAY [localhost] *************************************************************************************************************************************

TASK [My first task for executing hello world] *******************************************************************************************************
changed: [localhost]

TASK [My second task debug message name] *************************************************************************************************************
ok: [localhost] => {
    "msg": "my debug text"
}

TASK [My third task to print a text and variable] ****************************************************************************************************
ok: [localhost] => {
    "msg": "my debug text including var MY_VALUE"
}

PLAY RECAP *******************************************************************************************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

See also

Advertising: