-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansible_installation_in_python3.9_env.txt
352 lines (243 loc) · 7.89 KB
/
ansible_installation_in_python3.9_env.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
ansible installation on python3.9 virtual environment
1)
mkdir ansible_debug
cd ansible_debug
python3.9 -m venv venv
source venv/bin/activate
2)
To insall pyez
pip install junos-eznc
OR
To install the latest MASTER code
pip install git+https://github.com/Juniper/py-junos-eznc.git
OR
To install older release
pip install junos-eznc==2.6.0
3)
pip install jxmlease
pip install xmltodict
To innstall jsnapy specific version:
pip install jsnapy==1.3.7 --no-binary :all: --no-cache-dir
To install jsnapy 1.3.8 version
pip install jsnapy==1.3.8 --no-binary :all: --no-cache-dir
or
To install jnsapy from master
pip install git+https://github.com/Juniper/jsnapy.git
4)
To install ansible stable release:
pip install ansible
pip install ansible-core==2.14
OR
To install ansible developement release:
pip install ansible-core==2.14.0rc1
pip install https://github.com/ansible/ansible/archive/devel.tar.gz
OR
Ansible persistent connection working release
pip install ansible-core==2.12.7
ansible==5.4.0
ansible-core==2.12.7
OR
To install collection :
ansible-galaxy collection install juniper.device
OR
To install the developement collection
ansible-galaxy collection install git+https://github.com/Juniper/ansible-junos-stdlib.git#/ansible_collections/juniper/device
OR
To clone the developement Collection for dev and debugging
git clone https://github.com/Juniper/ansible-junos-stdlib.git
cd ansible-junos-stdlib
Dev installation for debugging
python setup.py install
OR
To install the v1.0.1 collection
ansible-galaxy collection install juniper.device:1.0.1
5)
To check the installed version
sudo ansible-galaxy collection list
6)
find ./ -name ansible.cfg
./ansible-junos-stdlib/tests/ansible.cfg
cat ansible.cfg
[defaults]
inventory = inventory
host_key_checking = False
[defaults]
hash_behaviour=merge
#roles_path = ~/.ansible/roles
inventory = inventory
host_key_checking = False
log_path = ./ansible.log
timeout=120
Update inventory file with following details .
which python3.9
vi ./ansible-junos-stdlib/tests/inventory
[junos]
test ansible_host=xx.xx.xx.xx ansible_user=xyz ansible_pass=xyz ansible_ssh_pass=xyz ansible_port=22
[all:vars]
ansible_python_interpreter=/root/ansbile_debug/venv/bin/python3.9
create ansible playbook
---
- name: 'Get config using collections'
hosts: junos
serial: 1
connection: local
gather_facts: no
collections:
- juniper.device
tasks:
- name: Retrieve the committed configuration
config:
retrieve: 'committed'
format: 'set'
dest_dir: "{{ playbook_dir }}/roles/junos_config/files/configs/set"
register: response
- name: Print the lines in the config.
debug:
var: response.config_lines
ansible-playbook get_config.yaml
PLAY [Test juniper_junos_config module] ************************************************************************************************************************************************************
TASK [Retrieve the committed configuration] ********************************************************************************************************************************************************
ok: [test]
TASK [Check TEST 1] ********************************************************************************************************************************************************************************
ok: [test] => {
"test1": {
"changed": false,
TO remove:
ansible-galaxy remove juniper.junos
Ansible Roles:
---
- name: Test juniper_junos_config module
hosts: all
connection: local
gather_facts: no
roles:
- juniper.junos
tasks:
#################
- name: Retrieve the committed configuration
juniper_junos_config:
retrieve: 'committed'
diff: false
check: false
commit: false
register: test1
ignore_errors: True
tags: [ test1 ]
- name: Check TEST 1
debug:
var: test1
================================
Ansible Debug :
================================
export ANSIBLE_DEBUG=True
export ANSIBLE_KEEP_REMOTE_FILES=1
Ansible Module debugging:
------------------------
add raise exception:
raise ValueError("value: '%s'" % value)
export ANSIBLE_KEEP_REMOTE_FILES=1
ansible-playbook test_config_set_login_message.yml -vvvvv
cd /root/.ansible/tmp/ansible-tmp-1683099427.4391778-11868-152799521893049/AnsiballZ_config.py
python AnsiballZ_config.py explode
cd ./debug_dir
cat args
python AnsiballZ_config.py execute
python -m pdb AnsiballZ_config.py execute
debug collection paths:
[defaults]
hash_behaviour=merge
roles_path = ~/.ansible/roles
inventory = inventory
host_key_checking = False
log_path = ./ansible.log
collections_paths = /root/ansible_get_unresolved_route/ansible-junos-stdlib/ansible_collections
sphinx documentation:
https://docs.readthedocs.io/en/stable/intro/getting-started-with-sphinx.html
pip install sphinx
pip install sphinx_bootstrap_theme
i) Within repo, cd docs
ii) sphinx-build -b html . _build/html/
Note:
For python3.9 below
pip install MarkupSafe==2.0.0
To build rst files
sphinx-apidoc -o . -f ../plugins/modules/
sphinx-build -b html . _build/html/
To build new module.rst files :
comment out the line from ansible_collections/juniper/device/docs/ansible2rst.py
# here is where we build the table of contents...
text = template.render(doc)
write_data(text, outputname, module_name, OUTPUTDIR)
python3 ansible2rst.py
sphinx-build -b html . _build/html/
tables and views debugging :
from jnpr.junos import Device
from jnpr.junos.factory.factory_loader import FactoryLoader
import yamlordereddictloader
import yaml
yaml_data="""
---
ARPtable:
command: show arp no-resolve
platform: juniper_junos
key:
- mac
- ip
use_textfsm: True
view: ARPview
ARPview:
fields:
mac: MAC
ip: IP_ADDRESS
interface: INTERFACE
flag: FLAGS
"""
dev = Device(host='xx.xx.xx.xx', user='xyz', password='xyz', gather_facts=False)
dev.open()
globals().update(FactoryLoader().load(yaml.load(yaml_data,Loader=yamlordereddictloader.Loader)))
arps = ARPtable(dev)
arps.get()
for arp in arps:
print ('mac_address: ', arp.mac)
print ('ip_address: ', arp.ip)
print ('interface_name:', arp.interface)
print ('flag:', arp.flag)
dev.close()
fix:
supported versions
pip install ntc_templates==1.4.1
pip install textfsm==0.4.1
================================================================================================
known issues:
================================================================================================
Ansible:
fix1:
./venv/lib/python3.9/site-packages/ansible/executor/task_executor.py
# deals with networking sub_plugins (network_cli/httpapi/netconf)
sub = getattr(self._connection, '_sub_plugin', None)
if sub and sub.get('type') != 'external':
plugin_type = get_plugin_class(sub.get("obj"))
varnames.extend(self._set_plugin_options(plugin_type, variables, templar, task_keys))
sub_conn = getattr(self._connection, 'ssh_type_conn', None)
if sub_conn is not None:
varnames.extend(self._set_plugin_options("ssh_type_conn", variables, templar, task_keys))
To take the patch diff from pull requests
https://github.com/Juniper/ansible-junos-stdlib/pull/650.patch
Ansible ssh_config option:
Host Test
HostName xx.xx.xx.xx
User root
IdentityFile ~/.ssh/id_rsa
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
ssh-copy-id [email protected]
Last login: Fri May 3 13:57:04 2024 from 10.220.0.191
--- JUNOS 21.4R3-S2.3 Kernel 64-bit JNPR-12.1-20221028.898be19_buil