-2

So this is conditionals on Ansible:

- debug:
        var: x
      when: x is not defined

Is there anyway to apply conditionals for junos_commands? Like:

  tasks:
    - name: Show logs
      junos_command:
        commands:
        - show interfaces
      when: apply this condition
  • You can apply conditions to any task. What condition in particular are you looking to use? Have you tried? What happened? – larsks Nov 30 '18 at 13:50

1 Answers1

1

Yes, you can use when with junos_command but you need to apply conditions to the when statement. For example:

yum:
  name: iotop
  state: present
when: ansible_os_family == "RedHat"

This will install iotop only if system is a RedHat family. You can also apply conditions from scripts or tasks that were run before and you have registered there result. More information can be find here: https://docs.ansible.com/ansible/2.7/user_guide/playbooks_conditionals.html

user3499202
  • 71
  • 1
  • 6