7

Ansible ( SaltStack) , . , ( ). , Ansible , . CLI, Ansible , .

 Ansible

" "

, , :

  • Ansible SSH ( ).
  • Ansible .
  • Ansible , , .

, Ansible. 3 , , . , . , .

- (playbook). (play) (task). .

YAML. , , JSON. Python, , .

( ):

  1. ;
  2. cisco-routers;
  3. ( , );
  4. task ;

:

PLAY [Run show commands on routers] ***************************************************

TASK [run sh ip int br] ***************************************************************
changed: [192.168.100.1]
changed: [192.168.100.3]
changed: [192.168.100.2]

TASK [run sh ip route] ****************************************************************
changed: [192.168.100.1]
changed: [192.168.100.3]
changed: [192.168.100.2]

PLAY [Run show commands on switches] **************************************************

TASK [run sh int status] **************************************************************
changed: [192.168.100.100]

TASK [run sh vlans] *******************************************************************
changed: [192.168.100.100]

PLAY RECAP ****************************************************************************
192.168.100.1			: ok=2	changed=2		unreachable=0	failed=0
192.168.100.100			: ok=2	changed=2		unreachable=0	failed=0
192.168.100.2			: ok=2	changed=2		unreachable=0	failed=0
192.168.100.3			: ok=2	changed=2		unreachable=0	failed=0

:

SSH password:

PLAY [Run show commands on routers] ***************************************************

TASK [run s hip int br] ***************************************************************
Changed: [192.168.100.1] => {changed: true, rc: 0, stderr: Shared connection 
To 192.168.100.1 closed.\r\n, stdout: \r\nInterface  			  IP-Address
    OK? Method Status			Protocol\r\nEthernet0/0 			  192.
168.100.1  YES NVRAM up				up	\r\nEthernet0/1
 192.168.200.1  YES NVRAM up				up	\r\nLoopback0
10.1.1.1	  YES manual up				up	\r\n, stdout_lines
: [, Interface			IP-Address OK? Method Status
  Protocol, Ethernet0/0			192.168.100.1  YES NVRAM up
 up	  , Ethernet0/1				192.168.200.1  YES NVRAM up
up	, Loopaback0				10.1.1.1	YES manual up
up	]}
?

. . , , .

. :

  1. , ;
  2. .

:

[cisco-routers]
192.168.100.1
192.168.100.2
192.168.100.3

[cisco-switches]
192.168.100.100

[cisco-routers:vars]
ntp_server=192.168.255.100
log_server=10.255.100.1

PLAYBOOK

-name: Run show commands on router:
 hosts: cisco-routers
 gather_facts: false

vars:
	ntp_server: 192.168.255.100
	log_server: 10.255.100.1

      tasks:
													
-name: run sh ip int br
 raw: s hip int br | ex unass

-name: run s hip route
 raw: sh ip route

, :

[cisco-routers]
192.168.100.1
192.168.100.2
192.168.100.3

[cisco-switches]
192.168.100.100

| group_vars			_
|   | all.yml			  |
|   |cisco-routers.yml	  |       
|   |cisco-switches.yml	_|
|
|host vars			_
|   |192.168.100.1		  |
|   |192.168.100.2		  |
|   |192.168.100.3		  |      
|   |192.168.100.100		_|
|
|myhosts			  |    	  

register . , .

---

	- name: Run show commands on routers
	  hosts: cisco-routers
	  gather_facts: false

	  tasks:

-name: run s hip int br
 raw: s hip int br | ex unass
 register: sh_ip_int_br_result

--- 

debug , .

---
- name: Run show commands on routers
  hosts: cisco-routers
  gather_facts: false

tasks:

	-name: run s hip int br
	 raw: sh ip int br | ex unass
	 register: sh_ip_int_br_result

	-name: Debug registered var
	 debug: var=sh_ip_int_br_result.stdout_lines

:

SSH password:

PLAY [Run show commands on routers] ***************************************************

TASK [run sh ip int br] ***************************************************************
changed: [192.168.100.1]
changed: [192.168.100.2]
changed: [192.168.100.3]

TASK [Debug registered var] ***********************************************************
ok: [192.168.100.1] => {
	sh_ip_int_br_result.stdout_lines: [
	,
	Interface			IP-Address	 	OK? Method Status			Protocol,
	Ethernet0/0		192.168.100.1	YES NVRAM  up			up	  ,
	Ethernet0/1		192.168.200.1	YES NVRAM  up			up	  ,
	Loopback0			10.1.1.1		YES manual up			up	  
    ]
}
ok: [192.168.100.2] => {
    sh_ip_int_br_result.stdout_lines: [
	  ,
	Interface			IP-Address	 	OK? Method Status			Protocol,
	Ethernet0/0		192.168.100.1	YES NVRAM  up			up	  ,
	Ethernet0/2		192.168.200.1	YES NVRAM  administratively down down ,
	Loopback0			10.1.1.1		YES manual up			up	  
    ]
}
ok: [192.168.100.3] => {
    sh_ip_int_br_result.stdout_lines: [
	  ,
	Interface			IP-Address	 	OK? Method Status			Protocol,
	Ethernet0/0		192.168.100.3	YES NVRAM  up			up	  ,
	Ethernet0/2		192.168.200.1	YES NVRAM  administratively down down ,
	Loopback0			10.1.1.1		YES manual up			up	  ,
Loopback10			10.255.3.3		YES manual up			up	  
    ]
}

PLAY RECAP ****************************************************************************
192.168.100.1			: ok=2	changed=1		unreachable=0	failed=0
192.168.100.2			: ok=2	changed=1		unreachable=0	failed=0
192.168.100.3			: ok=2	changed=1		unreachable=0	failed=0

, " ". Ansible , . . - , .


50% Merion Academy