Skip to content

Commit f4f2bb0

Browse files
Merge pull request #39 from ansible-network/bt_add_network_dir_in_role
Add network dir in module utils, update import statements Reviewed-by: https://github.com/ansible-zuul[bot]
2 parents cefc56d + 8f5ed45 commit f4f2bb0

File tree

22 files changed

+96
-87
lines changed

22 files changed

+96
-87
lines changed

README.md

Lines changed: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -76,33 +76,37 @@ ansible-playbook -e parent=~/github/rm_example \
7676
│   │   └── myos_interfaces.py
7777
│   └── module_utils
7878
│   ├── __init__.py
79-
│   └── myos
80-
│   ├── argspec
81-
│   │   ├── facts
82-
│   │   │   ├── facts.py
83-
│   │   │   └── __init__.py
84-
│   │   ├── __init__.py
85-
│   │   └── interfaces
86-
│   │   ├── __init__.py
87-
│   │   └── interfaces.py
88-
│   ├── config
89-
│   │   ├── base.py
90-
│   │   ├── __init__.py
91-
│   │   └── interfaces
92-
│   │   ├── __init__.py
93-
│   │   └── interfaces.py
94-
│   ├── facts
95-
│   │   ├── base.py
96-
│   │   ├── facts.py
97-
│   │   ├── __init__.py
98-
│   │   └── interfaces
99-
│   │   ├── __init__.py
100-
│   │   └── interfaces.py
79+
│   └── network
10180
│   ├── __init__.py
102-
│   └── utils
81+
│   └── myos
82+
│   ├── argspec
83+
│   │   ├── facts
84+
│   │   │   ├── facts.py
85+
│   │   │   └── __init__.py
86+
│   │   ├── __init__.py
87+
│   │   └── interfaces
88+
│   │   ├── __init__.py
89+
│   │   └── interfaces.py
90+
│   ├── config
91+
│   │   ├── base.py
92+
│   │   ├── __init__.py
93+
│   │   └── interfaces
94+
│   │   ├── __init__.py
95+
│   │   └── interfaces.py
96+
│   ├── facts
97+
│   │   ├── base.py
98+
│   │   ├── facts.py
99+
│   │   ├── __init__.py
100+
│   │   └── interfaces
101+
│   │   ├── __init__.py
102+
│   │   └── interfaces.py
103103
│   ├── __init__.py
104-
│   └── utils.py
105-
└── roles
104+
│   └── utils
105+
│   ├── __init__.py
106+
│   └── utils.py
107+
├── README.md
108+
├── roles
109+
106110
 
107111
```
108112
**Role directory layout**
@@ -118,40 +122,44 @@ ansible-playbook -e parent=~/github/rm_example/roles/my_role \
118122
```
119123

120124
```
121-
└── roles
122-
└── my_role
123-
├── library
124-
│   ├── __init__.py
125-
│   ├── myos_facts.py
126-
│   └── myos_interfaces.py
127-
└── module_utils
128-
├── __init__.py
129-
└── myos
130-
├── argspec
131-
│   ├── facts
132-
│   │   ├── facts.py
133-
│   │   └── __init__.py
134-
│   ├── __init__.py
135-
│   └── interfaces
136-
│   ├── __init__.py
137-
│   └── interfaces.py
138-
├── config
139-
│   ├── base.py
140-
│   ├── __init__.py
141-
│   └── interfaces
142-
│   ├── __init__.py
143-
│   └── interfaces.py
144-
├── facts
145-
│   ├── base.py
146-
│   ├── facts.py
147-
│   ├── __init__.py
148-
│   └── interfaces
149-
│   ├── __init__.py
150-
│   └── interfaces.py
151-
├── __init__.py
152-
└── utils
153-
├── __init__.py
154-
└── utils.py
125+
roles
126+
└── my_role
127+
├── library
128+
│   ├── __init__.py
129+
│   ├── myos_facts.py
130+
│   └── myos_interfaces.py
131+
├── LICENSE.txt
132+
├── module_utils
133+
│   ├── __init__.py
134+
│   └── network
135+
│   ├── __init__.py
136+
│   └── myos
137+
│   ├── argspec
138+
│   │   ├── facts
139+
│   │   │   ├── facts.py
140+
│   │   │   └── __init__.py
141+
│   │   ├── __init__.py
142+
│   │   └── interfaces
143+
│   │   ├── __init__.py
144+
│   │   └── interfaces.py
145+
│   ├── config
146+
│   │   ├── base.py
147+
│   │   ├── __init__.py
148+
│   │   └── interfaces
149+
│   │   ├── __init__.py
150+
│   │   └── interfaces.py
151+
│   ├── facts
152+
│   │   ├── base.py
153+
│   │   ├── facts.py
154+
│   │   ├── __init__.py
155+
│   │   └── interfaces
156+
│   │   ├── __init__.py
157+
│   │   └── interfaces.py
158+
│   ├── __init__.py
159+
│   └── utils
160+
│   ├── __init__.py
161+
│   └── utils.py
162+
└── README.md
155163
```
156164

157165
**Using the collection layout**

roles/resource_module/vars/main.yml

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,22 @@ import_paths:
2121
role: ansible.module_utils
2222
collection: "ansible_collections.{{ collection_org|default('') }}.{{ collection_name|default('') }}.plugins.module_utils"
2323

24-
import_path: "{{ import_paths[structure] }}"
24+
import_path: "{{ import_paths[structure] }}.network"
2525

2626
# all the directories that need to be built
2727
resource_module_directories:
2828
- "{{ module_directory }}"
2929
- module_utils
30-
- module_utils/{{ network_os }}
31-
- module_utils/{{ network_os }}/argspec
32-
- module_utils/{{ network_os }}/argspec/facts
33-
- module_utils/{{ network_os }}/argspec/{{ resource }}
34-
- module_utils/{{ network_os }}/config
35-
- module_utils/{{ network_os }}/config/{{ resource }}
36-
- module_utils/{{ network_os }}/facts
37-
- module_utils/{{ network_os }}/facts/{{ resource }}
38-
- module_utils/{{ network_os }}/utils
30+
- module_utils/network
31+
- module_utils/network/{{ network_os }}
32+
- module_utils/network/{{ network_os }}/argspec
33+
- module_utils/network/{{ network_os }}/argspec/facts
34+
- module_utils/network/{{ network_os }}/argspec/{{ resource }}
35+
- module_utils/network/{{ network_os }}/config
36+
- module_utils/network/{{ network_os }}/config/{{ resource }}
37+
- module_utils/network/{{ network_os }}/facts
38+
- module_utils/network/{{ network_os }}/facts/{{ resource }}
39+
- module_utils/network/{{ network_os }}/utils
3940

4041
# each of the files to be templated
4142
resource_module_templates:
@@ -49,26 +50,26 @@ resource_module_templates:
4950
destination: "{{ parent_directory }}/{{ module_directory }}/{{ network_os }}_facts.py"
5051
overwrite: False
5152
- source: module_utils/network_os/argspec/facts/facts.py.j2
52-
destination: "{{ parent_directory}}/module_utils/{{ network_os }}/argspec/facts/facts.py"
53+
destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/argspec/facts/facts.py"
5354
overwrite: False
5455
- source: module_utils/network_os/argspec/resource/resource.py.j2
55-
destination: "{{ parent_directory }}/module_utils/{{ network_os }}/argspec/{{ resource }}/{{ resource }}.py"
56+
destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/argspec/{{ resource }}/{{ resource }}.py"
5657
overwrite: True
5758
- source: module_utils/network_os/config/base.py.j2
58-
destination: "{{ parent_directory }}/module_utils/{{ network_os }}/config/base.py"
59+
destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/config/base.py"
5960
overwrite: False
6061
- source: module_utils/network_os/config/resource/resource.py.j2
61-
destination: "{{ parent_directory }}/module_utils/{{ network_os }}/config/{{ resource }}/{{ resource }}.py"
62+
destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/config/{{ resource }}/{{ resource }}.py"
6263
overwrite: False
6364
- source: module_utils/network_os/facts/base.py.j2
64-
destination: "{{ parent_directory }}/module_utils/{{ network_os }}/facts/base.py"
65+
destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/facts/base.py"
6566
overwrite: False
6667
- source: module_utils/network_os/facts/facts.py.j2
67-
destination: "{{ parent_directory}}/module_utils/{{ network_os }}/facts/facts.py"
68+
destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/facts/facts.py"
6869
overwrite: False
6970
- source: module_utils/network_os/facts/resource/resource.py.j2
70-
destination: "{{ parent_directory}}/module_utils/{{ network_os }}/facts/{{ resource }}/{{ resource }}.py"
71+
destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/facts/{{ resource }}/{{ resource }}.py"
7172
overwrite: False
7273
- source: module_utils/network_os/utils/utils.py.j2
73-
destination: "{{ parent_directory}}/module_utils/{{ network_os }}/utils/utils.py"
74+
destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/utils/utils.py"
7475
overwrite: False

tests/roles/my_role/library/myos_facts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from __future__ import absolute_import, division, print_function
1111
from ansible.module_utils.basic import AnsibleModule
1212
from ansible.module_utils.connection import Connection
13-
from ansible.module_utils. \
13+
from ansible.module_utils.network. \
1414
myos.facts.facts import Facts
1515

1616
ANSIBLE_METADATA = {'metadata_version': '1.1',

tests/roles/my_role/library/myos_interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181

182182
# pylint: disable=C0413
183183
from ansible.module_utils.basic import AnsibleModule
184-
from ansible.module_utils. \
184+
from ansible.module_utils.network. \
185185
myos.config.interfaces.interfaces import Interfaces
186186
# pylint: enable=C0413
187187

0 commit comments

Comments
 (0)