Config sample: Ansible + VyOS

# Ansible + VyOS

## Prerequisite

- ansible v2.5
- module
    - http://docs.ansible.com/ansible/latest/vyos_l3_interface_module.html

## Inventory sample

```
[vyos]
    192.168.1.22 ansible_user=sysadmin ansible_network_os=vyos
```

## Playbook sample

```yaml
---
- name: test
  hosts: vyos
  connection: network_cli
  tasks:
    - name: test
      vyos_l3_interface:
        name: eth1
        ipv4: 192.168.0.10/24
```

## Test

- Add IP Address

```
$ ansible-playbook -i hosts vyos-coomand.yml --ask-pass
SSH password:

PLAY [test] *************************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************
ok: [192.168.1.22]

TASK [test] *************************************************************************************************************************************************************
changed: [192.168.1.22]

PLAY RECAP **************************************************************************************************************************************************************
192.168.1.22               : ok=2    changed=1    unreachable=0    failed=0
```

```shell_session
$ ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:97:d2:27 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.1/24 brd 192.168.0.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet 192.168.0.10/24 brd 192.168.0.255 scope global secondary eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe97:d227/64 scope link
       valid_lft forever preferred_lft forever
```

- remove IP address

```yaml
---
- name: test
  hosts: vyos
  connection: network_cli
  tasks:
    - name: test
      vyos_l3_interface:
        name: eth1
        ipv4: 192.168.0.10/24
        state: absent
```
```
$ ansible-playbook -i hosts vyos-coomand.yml --ask-pass
SSH password:

PLAY [test] *************************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************
ok: [192.168.1.22]

TASK [test] *************************************************************************************************************************************************************
changed: [192.168.1.22]

PLAY RECAP **************************************************************************************************************************************************************
192.168.1.22               : ok=2    changed=1    unreachable=0    failed=0
```
```shell-session
$ ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:97:d2:27 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.1/24 brd 192.168.0.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe97:d227/64 scope link
       valid_lft forever preferred_lft forever
```