debug output for task

28 views
Skip to first unread message

Cyberbob

unread,
Mar 20, 2018, 1:25:49 PM3/20/18
to Ansible Project
Hi team,
i have this playbook:

---
- hosts: "{{ leaf_name }}"
  gather_facts: no
  connection: local
 
  vars_prompt:

  - name: "leaf_name"
    prompt: "Enter switch hostname/ip"
    private: no
  - name: "vlan_id"
    prompt: "Enter access vlan  for L2 ACCESS setup (example 10)"
    private: no

  vars:
    cli:
      username: admin
      password: password
      transport: cli

  tasks:

  - name: Checking configuration for  vlan {{ vlan_id }}
    ignore_errors: true
    nxos_command:
      commands: show vlan id {{ vlan_id }}
      provider: "{{ cli }}"
    register: output
    

  - debug: var=output.stdout_lines
  - debug:
      msg="Looks like  switch {{ leaf_name }} has no vlan {{ vlan_id }}."
    when: output.stdout_lines is not defined

The questions is: i want to get output if van exist and get message "Looks like  switch {{ leaf_name }} has no vlan {{ vlan_id }}" if it doesn't. 
What i must add to this playbook ?

Cyberbob

unread,
Mar 21, 2018, 7:18:54 AM3/21/18
to Ansible Project
team, 
any ideas?

вторник, 20 марта 2018 г., 20:25:49 UTC+3 пользователь Cyberbob написал:

Kai Stian Olstad

unread,
Mar 22, 2018, 4:26:44 PM3/22/18
to ansible...@googlegroups.com
output.stdout_lines is always defined so this will never run.


> The questions is: i want to get output if van exist and get message
> "Looks
> like switch {{ leaf_name }} has no vlan {{ vlan_id }}" if it doesn't.
> What i must add to this playbook ?

Hard to say, I have never used the nxos_command.
It's always a good idea to provide the content of your output variable,
because then you can get help from people that haven't used that module.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages