Split stdout based on white space

Hi All,

Request your help on the below

  • name: Check whether run level is set to Multi-User System
    command: runlevel
    register: rlevel_status
    failed_when: rlevel_status.stdout.split()[1] != 3

The output of rlevel_status = “N 3”

Error:

FAILED! => {“changed”: false, “cmd”: [“runlevel”], “delta”: “0:00:00.003175”, “end”: “2018-03-12 06:23:16.055125”, “failed”: true, “failed_when_result”: true, “rc”: 0, “start”: “2018-03-12 06:23:16.051950”, “stderr”: “”, “stderr_lines”: , “stdout”: “N 3”, “stdout_lines”: [“N 3”]}

From,
Vino.B

​​Hi

try comparing strings with strings, i.e.:

failed_when: rlevel_status.stdout.split()[1] != ‘3’

regards,
Thomas