2
---
- hosts: all
  gather_facts: false
  user: 
  become: yes

  tasks:

  - name: Checking current kernel on Target Server
    shell: hostname;uname -r
    register: output
  - debug: msg= "{{ output.stdout }}"
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
vijdhanz
  • 21
  • 1
  • 2

2 Answers2

4

Remove the space after "=". Correct syntax is

- debug: msg="{{ output.stdout }}"

, or

- debug:
    var: output.stdout

, or even better

- debug:
    var: output.stdout_lines
Vladimir Botka
  • 5,138
  • 8
  • 20
3

While Vladimir is correct about dumping out stdout of commands with debug, kernel release and hostname can be accessed with a minimal amount of fact collection:

---
- hosts: all
  gather_facts: True
  gather_subset: min
  become: False

  tasks:
  - name: hostname
    debug:
      var: ansible_hostname

  - name: kernel version
    debug: 
      var: ansible_kernel
  • Your variables are available without registering anything. You also get some bonus facts like ansible_distribution
  • The min facts set is sufficient, which skips a lot of hardware detection and is fairly fast.
  • Becoming a privileged user was not necessary.
  • Avoided a use of shell. Which has less obvious failure modes than fact collection.
John Mahowald
  • 32,050
  • 2
  • 19
  • 34