This commit is contained in:
Casual 2024-06-11 01:56:36 +03:00
parent 95167c7d2f
commit cafd9f6b30

View File

@ -118,7 +118,7 @@ Example output:
} }
} }
``` ```
3. Chech that all hosts accessable by ansible - `ansible all -m ping -i inventory.ini` 3. Check that all hosts accessable by ansible - `ansible all -m ping -i inventory.ini`
```sh ```sh
192.168.0.13 | UNREACHABLE! => { 192.168.0.13 | UNREACHABLE! => {
"changed": false, "changed": false,
@ -167,13 +167,13 @@ As you can see, we have `UNREACHABLE!` host - it's router and we can't access it
[all:vars] [all:vars]
ansible_user=ssh_connect_user #SSH user to connect ansible_user=ssh_connect_user #SSH user to connect
``` ```
If we would have many hosts in `routers` we would use solution 3, but we can use solution 2. If we would have many hosts in `routers` we would use solution 3, but we can use solution 2.
Run `ansible all -m ping -i inventory.ini` again Run `ansible all -m ping -i inventory.ini` again
If you still get `Permission denied` - then you forgot to `ssh-copy-id vyos@192.168.0.13` If you still get `Permission denied` - then you forgot to `ssh-copy-id vyos@192.168.0.13`
3. Create `playbook.yaml` 3. Create `playbook.yaml`
We will start with easiest task - dump config from router. We will start with easiest task - dump config from router.
`playbook.yaml`: `playbook.yaml`:
```yaml ```yaml
- name: dump config from router - name: dump config from router
@ -187,9 +187,9 @@ We will start with easiest task - dump config from router.
filename: ./backup.cfg filename: ./backup.cfg
``` ```
All `.yaml` files uses `YAML` so exact number of spaces IS IMPORTANT All `.yaml` files uses `YAML` so exact number of spaces IS IMPORTANT
Then run playbook - `ansible-playbook -i inventory.ini playbook.yaml` Then run playbook - `ansible-playbook -i inventory.ini playbook.yaml`
```sh ```sh
PLAY [dump config from router] ************************************************************** PLAY [dump config from router] **************************************************************
@ -236,12 +236,12 @@ ansibleExample ➤ cat backup.cfg
set interfaces ethernet eth1 address 'dhcp' set interfaces ethernet eth1 address 'dhcp'
... ...
``` ```
We successfully backuped config! We successfully backuped config!
But where did I found `vyos.vyos.vyos_config` and its parameters? But where did I found `vyos.vyos.vyos_config` and its parameters?
__Search in [Ansible Docs](https://docs.ansible.com/ansible/latest/index.html) or Google.__ __Search in [Ansible Docs](https://docs.ansible.com/ansible/latest/index.html) or Google.__
4. Create role for PCs - `mkdir roles; cd roles; ansible-galaxy init [Name]` 4. Create role for PCs - `mkdir roles; cd roles; ansible-galaxy init [Name]`
5. Edit `playbook.yaml` 5. Edit `playbook.yaml`
`playbook.yaml`: `playbook.yaml`:
@ -277,7 +277,7 @@ PLAY RECAP *********************************************************************
192.168.0.5 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.0.5 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
``` ```
Everything fine. Everything fine.
6. Edit role's tasks - `roles/web-browser/tasks/main.yml`: 6. Edit role's tasks - `roles/web-browser/tasks/main.yml`:
```yaml ```yaml