mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-30 18:36:28 +00:00
Compare commits
431 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5f290e885 | ||
|
|
003f9e498e | ||
|
|
700bb27d51 | ||
|
|
07c68cb7f1 | ||
|
|
e9f0fcac0d | ||
|
|
a2e198d8a7 | ||
|
|
9ccb6e029d | ||
|
|
adf0f41b4b | ||
|
|
63a8f1e89f | ||
|
|
76de353377 | ||
|
|
960ed5acfd | ||
|
|
f636201450 | ||
|
|
fb01bf6ff7 | ||
|
|
8569e7eb58 | ||
|
|
c100ecda2c | ||
|
|
f33f50cf2c | ||
|
|
452d6f2fa7 | ||
|
|
f3828ba9ca | ||
|
|
b4eb8e5e22 | ||
|
|
8c02531c56 | ||
|
|
41171a02b7 | ||
|
|
84a6f610f7 | ||
|
|
2f623b7398 | ||
|
|
4e73ae1a86 | ||
|
|
392f5b4702 | ||
|
|
d5d8e1d188 | ||
|
|
fbd0a80439 | ||
|
|
c55df29ec9 | ||
|
|
2405857338 | ||
|
|
1c6b9507bc | ||
|
|
9363356941 | ||
|
|
7b92d84878 | ||
|
|
c8fe77c359 | ||
|
|
d5465ff471 | ||
|
|
7cd8f6edff | ||
|
|
125cafb371 | ||
|
|
9e11cd0813 | ||
|
|
2b48825499 | ||
|
|
8196cacff8 | ||
|
|
bd4f1a3e5c | ||
|
|
cfee3284cd | ||
|
|
9c3e14701b | ||
|
|
cae0457e0e | ||
|
|
a9e892952d | ||
|
|
e8ff74f077 | ||
|
|
0478b0c5a1 | ||
|
|
4a642c247c | ||
|
|
8bffd757ce | ||
|
|
eb294ae86e | ||
|
|
cea886562a | ||
|
|
30c5de00e9 | ||
|
|
ae3236389e | ||
|
|
9717bac816 | ||
|
|
6b5b051c3d | ||
|
|
5d7ff825de | ||
|
|
f58ab1b642 | ||
|
|
f644720c74 | ||
|
|
7a0428d7e6 | ||
|
|
b3eadab36a | ||
|
|
17280ed73e | ||
|
|
207ea056a7 | ||
|
|
f7189a55c6 | ||
|
|
edb0d5f6ca | ||
|
|
4c6f77cbc5 | ||
|
|
3b812e64ff | ||
|
|
3856c184d2 | ||
|
|
facdfb9519 | ||
|
|
1f90168f37 | ||
|
|
f238b90fcf | ||
|
|
9d245287b2 | ||
|
|
8c8e755369 | ||
|
|
946727309f | ||
|
|
bc716b7ab4 | ||
|
|
8ab0591e85 | ||
|
|
d557997242 | ||
|
|
e116cccb82 | ||
|
|
301483a7f3 | ||
|
|
61c326ce81 | ||
|
|
4e35837063 | ||
|
|
0dc63be643 | ||
|
|
14e2dd4cea | ||
|
|
3e5d58129d | ||
|
|
79241e672f | ||
|
|
12415f3e2f | ||
|
|
ca478eb38d | ||
|
|
aeb668a645 | ||
|
|
7b83b7f7bb | ||
|
|
0e1c4a20c2 | ||
|
|
70bf4e449c | ||
|
|
ac8942979b | ||
|
|
28fb1e3eac | ||
|
|
2fabb55a4d | ||
|
|
41b624ffaf | ||
|
|
e2283faf98 | ||
|
|
af276713aa | ||
|
|
68c3c9b7ba | ||
|
|
7bb291864e | ||
|
|
0090af8cfb | ||
|
|
42aeeb975b | ||
|
|
9dd7be05dc | ||
|
|
11a847a7b5 | ||
|
|
ebcceafdb7 | ||
|
|
79b3521547 | ||
|
|
7aae8a94f2 | ||
|
|
acde075b5f | ||
|
|
0310c7875d | ||
|
|
8bce7601bc | ||
|
|
ab5c4b186b | ||
|
|
ee2779e6c1 | ||
|
|
91ac9f84b8 | ||
|
|
1c1d58482c | ||
|
|
138740127a | ||
|
|
1d7aad9b46 | ||
|
|
f3a12a9e78 | ||
|
|
0e818c4812 | ||
|
|
8751f0feea | ||
|
|
5dd4cc5148 | ||
|
|
39f27d7d43 | ||
|
|
4dec46778c | ||
|
|
d5e0d36e48 | ||
|
|
fb45b908dd | ||
|
|
6e16c6c649 | ||
|
|
033d5f23f8 | ||
|
|
6367bb853d | ||
|
|
8e6941ed5d | ||
|
|
2d730da8a7 | ||
|
|
88f5100657 | ||
|
|
0293f84b3e | ||
|
|
8333c881d3 | ||
|
|
4a394088b3 | ||
|
|
d72d9b3e45 | ||
|
|
e44bbbdcba | ||
|
|
eca7c1a00b | ||
|
|
b1ff713c41 | ||
|
|
c95a8b6540 | ||
|
|
57dcd31c82 | ||
|
|
7ba3d84004 | ||
|
|
837c1289d0 | ||
|
|
3c7c946297 | ||
|
|
f0f5035ba2 | ||
|
|
3955a6be0f | ||
|
|
bc5b4bdef3 | ||
|
|
8f8b1ee4ce | ||
|
|
6534db4942 | ||
|
|
7a55295798 | ||
|
|
0fd7cfd2d6 | ||
|
|
68ca28b69a | ||
|
|
c91e7b4c03 | ||
|
|
2583152512 | ||
|
|
cee6c98d2a | ||
|
|
8859379bed | ||
|
|
e899631137 | ||
|
|
e99dcaa729 | ||
|
|
c12dd2f9c7 | ||
|
|
8253fb171d | ||
|
|
5f1f76b8f4 | ||
|
|
e3793e09e8 | ||
|
|
a800a6dbad | ||
|
|
7d45b678e4 | ||
|
|
cd0ca389ed | ||
|
|
9ebf72d560 | ||
|
|
d6a4fab8ea | ||
|
|
4e43b124cd | ||
|
|
9bcf61d153 | ||
|
|
7f5305fb80 | ||
|
|
aea60a8dd6 | ||
|
|
195ac4d7e6 | ||
|
|
91d515bd1e | ||
|
|
7d8f5559e2 | ||
|
|
9e68816db9 | ||
|
|
fc1ba5152c | ||
|
|
205e28d2fe | ||
|
|
27629b6497 | ||
|
|
5735c5a045 | ||
|
|
ceb051851e | ||
|
|
a17083ea84 | ||
|
|
d03fdc8093 | ||
|
|
469209a17f | ||
|
|
72ea96cc74 | ||
|
|
b2c34d1afe | ||
|
|
f4fca86f82 | ||
|
|
78c8fa0d49 | ||
|
|
d3650f27b0 | ||
|
|
7b901f9caa | ||
|
|
35d6ab10bb | ||
|
|
d811807e1f | ||
|
|
dedd625700 | ||
|
|
10e41862cb | ||
|
|
3d418d9ede | ||
|
|
ebb150c3f9 | ||
|
|
df28c80946 | ||
|
|
403152d91a | ||
|
|
75e35bfa6c | ||
|
|
fa846e9677 | ||
|
|
db62a36d6e | ||
|
|
e3dae0b646 | ||
|
|
9aaf8e4825 | ||
|
|
cf0a233d7b | ||
|
|
cebd5bb3c8 | ||
|
|
d452e903f8 | ||
|
|
c76ef6ba99 | ||
|
|
52bd7cdb2d | ||
|
|
da3ba1e7be | ||
|
|
cb46453b78 | ||
|
|
a784e66a2c | ||
|
|
52cc1881d8 | ||
|
|
5c7076e0bc | ||
|
|
fc752f3143 | ||
|
|
4637c265fa | ||
|
|
33e980039b | ||
|
|
e49775765d | ||
|
|
c2590cfcd8 | ||
|
|
4282b6ed16 | ||
|
|
3c77c8ec3c | ||
|
|
07e4e4a782 | ||
|
|
d881a59ed7 | ||
|
|
338328341e | ||
|
|
6e48528b22 | ||
|
|
f545c300d9 | ||
|
|
df496e37c0 | ||
|
|
c35f13084d | ||
|
|
4d4e626f95 | ||
|
|
faa913d566 | ||
|
|
7e4a39964e | ||
|
|
c6aecd18f4 | ||
|
|
c5bdb1501e | ||
|
|
163bfd0f37 | ||
|
|
0331798f84 | ||
|
|
2c7940c5de | ||
|
|
4ef5c3c11a | ||
|
|
7468bf30f2 | ||
|
|
b4e7b7cb50 | ||
|
|
666db05eda | ||
|
|
e255e5ed0c | ||
|
|
f79aa6f63f | ||
|
|
da040cb412 | ||
|
|
04b68c296b | ||
|
|
8e2fa624e0 | ||
|
|
c7ac7fbefd | ||
|
|
ed6e87c994 | ||
|
|
cc49336090 | ||
|
|
4b410c5007 | ||
|
|
13be47c7a6 | ||
|
|
94903785d0 | ||
|
|
20e394fd3d | ||
|
|
17157cdfb5 | ||
|
|
769b22cd4c | ||
|
|
dbd19a5583 | ||
|
|
45f7661249 | ||
|
|
ed472d8291 | ||
|
|
c72d8d4b56 | ||
|
|
e9b58cfc09 | ||
|
|
98d25a3e4d | ||
|
|
7a000108af | ||
|
|
a8a1c0af2a | ||
|
|
c394fbe8e9 | ||
|
|
fed5965518 | ||
|
|
1e0a2a72f7 | ||
|
|
add595e121 | ||
|
|
4476a4bb1c | ||
|
|
f104fe3a58 | ||
|
|
1bc052ae6b | ||
|
|
6260d5f873 | ||
|
|
6907ae5a5e | ||
|
|
2314db59c7 | ||
|
|
e32515889b | ||
|
|
7542b5429b | ||
|
|
18afa4e8b0 | ||
|
|
b23d011582 | ||
|
|
8b56b6dfea | ||
|
|
c2a90c215f | ||
|
|
39a66a3196 | ||
|
|
75f649648e | ||
|
|
1f29fa2e39 | ||
|
|
26b8f30afa | ||
|
|
80f43bbbf5 | ||
|
|
ec58aadaa7 | ||
|
|
6f50af8a6e | ||
|
|
e2604e7533 | ||
|
|
8208e52c42 | ||
|
|
39e4f89ff0 | ||
|
|
c7202a1902 | ||
|
|
1f64be7cac | ||
|
|
2447bc90a4 | ||
|
|
98029089d8 | ||
|
|
964aa945a4 | ||
|
|
7d24ba8a28 | ||
|
|
be5b4adf5b | ||
|
|
62b45e235d | ||
|
|
f99508b307 | ||
|
|
9afc096cd2 | ||
|
|
27c0c29cf3 | ||
|
|
c890a161ae | ||
|
|
c911aa8a84 | ||
|
|
a3cb344689 | ||
|
|
bd4112e87b | ||
|
|
ec9b1fc503 | ||
|
|
5467334117 | ||
|
|
e962b9237d | ||
|
|
48c36bc72b | ||
|
|
56bb7d7b9d | ||
|
|
af2438f664 | ||
|
|
a68de9bfb6 | ||
|
|
4614047132 | ||
|
|
6b02eaa795 | ||
|
|
6f774fd4a5 | ||
|
|
f05618a6f2 | ||
|
|
98a956a9d6 | ||
|
|
60d51f7b49 | ||
|
|
245be47a4e | ||
|
|
6d346ddadd | ||
|
|
cb969fc468 | ||
|
|
ec6c2a76ad | ||
|
|
b22777de44 | ||
|
|
151f6c9ce3 | ||
|
|
0acaad60c8 | ||
|
|
a06c1f5c9a | ||
|
|
becda864c4 | ||
|
|
92d077e816 | ||
|
|
700623863c | ||
|
|
31f57b9385 | ||
|
|
14038511a1 | ||
|
|
3db0a11148 | ||
|
|
05ba79c5fe | ||
|
|
0df708b15a | ||
|
|
1829ad4fdc | ||
|
|
0e99b006a2 | ||
|
|
f66bd1035d | ||
|
|
7732d64abb | ||
|
|
03f3b74934 | ||
|
|
29e9afcbf4 | ||
|
|
11ba71c802 | ||
|
|
d3badc6d43 | ||
|
|
92a07f1794 | ||
|
|
7a44dbfe45 | ||
|
|
4f9e7bd793 | ||
|
|
872bc91096 | ||
|
|
641b0693b4 | ||
|
|
45a3396ab0 | ||
|
|
e38f9e5cfc | ||
|
|
60ba39da58 | ||
|
|
f6fa7fb273 | ||
|
|
899fcb8749 | ||
|
|
a5c448d6e8 | ||
|
|
74bd7f1471 | ||
|
|
7e6514b4d4 | ||
|
|
3c7f05c42d | ||
|
|
a13a6d284c | ||
|
|
122086e83b | ||
|
|
92e4bd184d | ||
|
|
12f2d71950 | ||
|
|
e3f72bca4f | ||
|
|
429b4b14a8 | ||
|
|
2d12c6678c | ||
|
|
474c7a7240 | ||
|
|
434032080e | ||
|
|
eec5c82a55 | ||
|
|
97ea891377 | ||
|
|
b3ad22f33f | ||
|
|
977f53f823 | ||
|
|
4c26dc0760 | ||
|
|
3c6131b451 | ||
|
|
2499c1132d | ||
|
|
3fe559b88f | ||
|
|
28fed38757 | ||
|
|
f2196d452f | ||
|
|
07124473cc | ||
|
|
a56cec8582 | ||
|
|
5c2e9e0c5b | ||
|
|
df5818282b | ||
|
|
69aea38683 | ||
|
|
01dce04e33 | ||
|
|
5ab43f0ff1 | ||
|
|
910fb933a7 | ||
|
|
7537674d4b | ||
|
|
6e42e442bc | ||
|
|
161539729d | ||
|
|
8f76c847fe | ||
|
|
3f29683191 | ||
|
|
a89990ab9b | ||
|
|
7bc937b5e8 | ||
|
|
a1c39cc882 | ||
|
|
859039c47a | ||
|
|
b3f669a574 | ||
|
|
770bae70db | ||
|
|
0a6c57bc4d | ||
|
|
459b9f3f9a | ||
|
|
d9436069f1 | ||
|
|
fcf1cb7fbc | ||
|
|
5727f1afd4 | ||
|
|
fbada0026e | ||
|
|
c4373d5ed5 | ||
|
|
54291ab1d1 | ||
|
|
bbd67b5017 | ||
|
|
6d6d3e8039 | ||
|
|
e31999f369 | ||
|
|
09f99e66fe | ||
|
|
5491ff7c6a | ||
|
|
163f3ee305 | ||
|
|
4152770281 | ||
|
|
ecc9afab0b | ||
|
|
6f9b954048 | ||
|
|
74cd18b682 | ||
|
|
0b64fc1ee4 | ||
|
|
5fe39082d5 | ||
|
|
0ff52abfdd | ||
|
|
653ae1b48a | ||
|
|
16d124bbe2 | ||
|
|
4455df380e | ||
|
|
06c7ba640e | ||
|
|
a6f6bcc555 | ||
|
|
cd06325f6b | ||
|
|
a20ee0e816 | ||
|
|
acb6a2f76d | ||
|
|
5a1c68cb62 | ||
|
|
776374ee78 | ||
|
|
c916052124 | ||
|
|
88b1fbbdf0 | ||
|
|
48db44f199 | ||
|
|
eb4c01260f | ||
|
|
10561e6f30 | ||
|
|
5c26387a54 | ||
|
|
8226ea87cf | ||
|
|
411c7d4f32 | ||
|
|
a2f377c621 | ||
|
|
ac0956ed6f | ||
|
|
0d02265a23 | ||
|
|
f38d974d42 | ||
|
|
a975574618 | ||
|
|
b05fa358e6 | ||
|
|
c44118ac3c |
@@ -70,6 +70,19 @@ stages:
|
||||
- test: 2
|
||||
- test: 3
|
||||
- test: 4
|
||||
- stage: Sanity_2_19
|
||||
displayName: Sanity 2.19
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
nameFormat: Test {0}
|
||||
testFormat: 2.19/sanity/{0}
|
||||
targets:
|
||||
- test: 1
|
||||
- test: 2
|
||||
- test: 3
|
||||
- test: 4
|
||||
- stage: Sanity_2_18
|
||||
displayName: Sanity 2.18
|
||||
dependsOn: []
|
||||
@@ -96,6 +109,19 @@ stages:
|
||||
- test: 2
|
||||
- test: 3
|
||||
- test: 4
|
||||
- stage: Sanity_2_16
|
||||
displayName: Sanity 2.16
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
nameFormat: Test {0}
|
||||
testFormat: 2.16/sanity/{0}
|
||||
targets:
|
||||
- test: 1
|
||||
- test: 2
|
||||
- test: 3
|
||||
- test: 4
|
||||
### Units
|
||||
- stage: Units_devel
|
||||
displayName: Units devel
|
||||
@@ -112,6 +138,17 @@ stages:
|
||||
- test: '3.11'
|
||||
- test: '3.12'
|
||||
- test: '3.13'
|
||||
- stage: Units_2_19
|
||||
displayName: Units 2.19
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
nameFormat: Python {0}
|
||||
testFormat: 2.19/units/{0}/1
|
||||
targets:
|
||||
- test: 3.9
|
||||
- test: "3.13"
|
||||
- stage: Units_2_18
|
||||
displayName: Units 2.18
|
||||
dependsOn: []
|
||||
@@ -134,6 +171,18 @@ stages:
|
||||
targets:
|
||||
- test: 3.7
|
||||
- test: "3.12"
|
||||
- stage: Units_2_16
|
||||
displayName: Units 2.16
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
nameFormat: Python {0}
|
||||
testFormat: 2.16/units/{0}/1
|
||||
targets:
|
||||
- test: 2.7
|
||||
- test: 3.6
|
||||
- test: "3.11"
|
||||
|
||||
## Remote
|
||||
- stage: Remote_devel_extra_vms
|
||||
@@ -176,6 +225,20 @@ stages:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- stage: Remote_2_19
|
||||
displayName: Remote 2.19
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
testFormat: 2.19/{0}
|
||||
targets:
|
||||
- name: RHEL 10.0
|
||||
test: rhel/10.0
|
||||
groups:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- stage: Remote_2_18
|
||||
displayName: Remote 2.18
|
||||
dependsOn: []
|
||||
@@ -210,6 +273,28 @@ stages:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- stage: Remote_2_16
|
||||
displayName: Remote 2.16
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
testFormat: 2.16/{0}
|
||||
targets:
|
||||
- name: macOS 13.2
|
||||
test: macos/13.2
|
||||
- name: RHEL 9.2
|
||||
test: rhel/9.2
|
||||
- name: RHEL 8.8
|
||||
test: rhel/8.8
|
||||
- name: RHEL 7.9
|
||||
test: rhel/7.9
|
||||
# - name: FreeBSD 13.2
|
||||
# test: freebsd/13.2
|
||||
groups:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
|
||||
### Docker
|
||||
- stage: Docker_devel
|
||||
@@ -232,6 +317,20 @@ stages:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- stage: Docker_2_19
|
||||
displayName: Docker 2.19
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
testFormat: 2.19/linux/{0}
|
||||
targets:
|
||||
- name: Ubuntu 24.04
|
||||
test: ubuntu2404
|
||||
groups:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- stage: Docker_2_18
|
||||
displayName: Docker 2.18
|
||||
dependsOn: []
|
||||
@@ -268,6 +367,26 @@ stages:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- stage: Docker_2_16
|
||||
displayName: Docker 2.16
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
testFormat: 2.16/linux/{0}
|
||||
targets:
|
||||
- name: Fedora 38
|
||||
test: fedora38
|
||||
- name: openSUSE 15
|
||||
test: opensuse15
|
||||
- name: Alpine 3
|
||||
test: alpine3
|
||||
- name: CentOS 7
|
||||
test: centos7
|
||||
groups:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
|
||||
### Community Docker
|
||||
- stage: Docker_community_devel
|
||||
@@ -303,6 +422,17 @@ stages:
|
||||
# - test: '3.8'
|
||||
# - test: '3.11'
|
||||
# - test: '3.13'
|
||||
# - stage: Generic_2_19
|
||||
# displayName: Generic 2.19
|
||||
# dependsOn: []
|
||||
# jobs:
|
||||
# - template: templates/matrix.yml
|
||||
# parameters:
|
||||
# nameFormat: Python {0}
|
||||
# testFormat: 2.19/generic/{0}/1
|
||||
# targets:
|
||||
# - test: '3.9'
|
||||
# - test: '3.13'
|
||||
# - stage: Generic_2_18
|
||||
# displayName: Generic 2.18
|
||||
# dependsOn: []
|
||||
@@ -325,27 +455,49 @@ stages:
|
||||
# targets:
|
||||
# - test: '3.7'
|
||||
# - test: '3.12'
|
||||
# - stage: Generic_2_16
|
||||
# displayName: Generic 2.16
|
||||
# dependsOn: []
|
||||
# jobs:
|
||||
# - template: templates/matrix.yml
|
||||
# parameters:
|
||||
# nameFormat: Python {0}
|
||||
# testFormat: 2.16/generic/{0}/1
|
||||
# targets:
|
||||
# - test: '2.7'
|
||||
# - test: '3.6'
|
||||
# - test: '3.11'
|
||||
|
||||
- stage: Summary
|
||||
condition: succeededOrFailed()
|
||||
dependsOn:
|
||||
- Sanity_devel
|
||||
- Sanity_2_19
|
||||
- Sanity_2_18
|
||||
- Sanity_2_17
|
||||
- Sanity_2_16
|
||||
- Units_devel
|
||||
- Units_2_19
|
||||
- Units_2_18
|
||||
- Units_2_17
|
||||
- Units_2_16
|
||||
- Remote_devel_extra_vms
|
||||
- Remote_devel
|
||||
- Remote_2_19
|
||||
- Remote_2_18
|
||||
- Remote_2_17
|
||||
- Remote_2_16
|
||||
- Docker_devel
|
||||
- Docker_2_19
|
||||
- Docker_2_18
|
||||
- Docker_2_17
|
||||
- Docker_2_16
|
||||
- Docker_community_devel
|
||||
# Right now all generic tests are disabled. Uncomment when at least one of them is re-enabled.
|
||||
# - Generic_devel
|
||||
# - Generic_2_19
|
||||
# - Generic_2_18
|
||||
# - Generic_2_17
|
||||
# - Generic_2_16
|
||||
jobs:
|
||||
- template: templates/coverage.yml
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# YAML reformatting
|
||||
d032de3b16eed11ea3a31cd3d96d78f7c46a2ee0
|
||||
e8f965fbf8154ea177c6622da149f2ae8533bd3c
|
||||
e938ca5f20651abc160ee6aba10014013d04dcc1
|
||||
eaa5e07b2866e05b6c7b5628ca92e9cb1142d008
|
||||
2b4882549908b5b1fafe5fa10efb47f613a71f94
|
||||
8196cacff8e83dc5d7fb88b43ef3cab5d3751c39
|
||||
bd4f1a3e5ca1af5afc53636c36767e81a4566978
|
||||
a9e892952deef6f91977d7032dd95237a9867509
|
||||
|
||||
50
.github/BOTMETA.yml
vendored
50
.github/BOTMETA.yml
vendored
@@ -113,6 +113,9 @@ files:
|
||||
$connections/lxd.py:
|
||||
labels: lxd
|
||||
maintainers: mattclay
|
||||
$connections/proxmox_pct_remote.py:
|
||||
labels: proxmox
|
||||
maintainers: mietzen
|
||||
$connections/qubes.py:
|
||||
maintainers: kushaldas
|
||||
$connections/saltstack.py:
|
||||
@@ -124,6 +127,8 @@ files:
|
||||
maintainers: $team_ansible_core
|
||||
$doc_fragments/:
|
||||
labels: docs_fragments
|
||||
$doc_fragments/clc.py:
|
||||
maintainers: clc-runner russoz
|
||||
$doc_fragments/django.py:
|
||||
maintainers: russoz
|
||||
$doc_fragments/hpe3par.py:
|
||||
@@ -244,9 +249,13 @@ files:
|
||||
keywords: opennebula dynamic inventory script
|
||||
labels: cloud opennebula
|
||||
maintainers: feldsam
|
||||
$inventories/proxmox.py:
|
||||
maintainers: $team_virt ilijamt krauthosting
|
||||
$inventories/scaleway.py:
|
||||
labels: cloud scaleway
|
||||
maintainers: $team_scaleway
|
||||
$inventories/stackpath_compute.py:
|
||||
maintainers: shayrybak
|
||||
$inventories/virtualbox.py: {}
|
||||
$inventories/xen_orchestra.py:
|
||||
maintainers: ddelnano shinuza
|
||||
@@ -290,6 +299,9 @@ files:
|
||||
$lookups/lastpass.py: {}
|
||||
$lookups/lmdb_kv.py:
|
||||
maintainers: jpmens
|
||||
$lookups/manifold.py:
|
||||
labels: manifold
|
||||
maintainers: galanoff
|
||||
$lookups/merge_variables.py:
|
||||
maintainers: rlenferink m-a-r-k-e alpex8
|
||||
$lookups/onepass:
|
||||
@@ -498,6 +510,8 @@ files:
|
||||
maintainers: NickatEpic
|
||||
$modules/cisco_webex.py:
|
||||
maintainers: drew-russell
|
||||
$modules/clc_:
|
||||
maintainers: clc-runner
|
||||
$modules/cloud_init_data_facts.py:
|
||||
maintainers: resmo
|
||||
$modules/cloudflare_dns.py:
|
||||
@@ -656,6 +670,8 @@ files:
|
||||
maintainers: marns93
|
||||
$modules/hg.py:
|
||||
maintainers: yeukhon
|
||||
$modules/hipchat.py:
|
||||
maintainers: pb8226 shirou
|
||||
$modules/homebrew.py:
|
||||
ignore: ryansb
|
||||
keywords: brew cask darwin homebrew macosx macports osx
|
||||
@@ -897,8 +913,6 @@ files:
|
||||
maintainers: nerzhul
|
||||
$modules/lvg.py:
|
||||
maintainers: abulimov
|
||||
$modules/lvm_pv.py:
|
||||
maintainers: klention
|
||||
$modules/lvg_rename.py:
|
||||
maintainers: lszomor
|
||||
$modules/lvol.py:
|
||||
@@ -1131,6 +1145,36 @@ files:
|
||||
maintainers: $team_bsd berenddeboer
|
||||
$modules/pritunl_:
|
||||
maintainers: Lowess
|
||||
$modules/profitbricks:
|
||||
maintainers: baldwinSPC
|
||||
$modules/proxmox:
|
||||
keywords: kvm libvirt proxmox qemu
|
||||
labels: proxmox virt
|
||||
maintainers: $team_virt UnderGreen krauthosting
|
||||
ignore: tleguern
|
||||
$modules/proxmox.py:
|
||||
ignore: skvidal
|
||||
maintainers: UnderGreen krauthosting
|
||||
$modules/proxmox_disk.py:
|
||||
maintainers: castorsky krauthosting
|
||||
$modules/proxmox_kvm.py:
|
||||
ignore: skvidal
|
||||
maintainers: helldorado krauthosting
|
||||
$modules/proxmox_backup.py:
|
||||
maintainers: IamLunchbox
|
||||
$modules/proxmox_backup_info.py:
|
||||
maintainers: raoufnezhad mmayabi
|
||||
$modules/proxmox_nic.py:
|
||||
maintainers: Kogelvis krauthosting
|
||||
$modules/proxmox_node_info.py:
|
||||
maintainers: jwbernin krauthosting
|
||||
$modules/proxmox_storage_contents_info.py:
|
||||
maintainers: l00ptr krauthosting
|
||||
$modules/proxmox_tasks_info:
|
||||
maintainers: paginabianca krauthosting
|
||||
$modules/proxmox_template.py:
|
||||
ignore: skvidal
|
||||
maintainers: UnderGreen krauthosting
|
||||
$modules/pubnub_blocks.py:
|
||||
maintainers: parfeon pubnub
|
||||
$modules/pulp_repo.py:
|
||||
@@ -1445,8 +1489,6 @@ files:
|
||||
maintainers: natefoo
|
||||
$modules/znode.py:
|
||||
maintainers: treyperry
|
||||
$modules/zpool.py:
|
||||
maintainers: tomhesse
|
||||
$modules/zpool_facts:
|
||||
keywords: beadm dladm illumos ipadm nexenta omnios openindiana pfexec smartos solaris sunos zfs zpool
|
||||
labels: solaris
|
||||
|
||||
4
.github/dependabot.yml
vendored
4
.github/dependabot.yml
vendored
@@ -9,7 +9,3 @@ updates:
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
groups:
|
||||
ci:
|
||||
patterns:
|
||||
- "*"
|
||||
|
||||
78
.github/workflows/ansible-test.yml
vendored
78
.github/workflows/ansible-test.yml
vendored
@@ -29,7 +29,12 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
ansible:
|
||||
- '2.16'
|
||||
- '2.15'
|
||||
# Ansible-test on various stable branches does not yet work well with cgroups v2.
|
||||
# Since ubuntu-latest now uses Ubuntu 22.04, we need to fall back to the ubuntu-20.04
|
||||
# image for these stable branches. The list of branches where this is necessary will
|
||||
# shrink over time, check out https://github.com/ansible-collections/news-for-maintainers/issues/28
|
||||
# for the latest list.
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Perform sanity testing
|
||||
@@ -44,6 +49,11 @@ jobs:
|
||||
git clone --depth=1 --single-branch https://github.com/ansible-collections/community.internal_test_tools.git ../../community/internal_test_tools
|
||||
|
||||
units:
|
||||
# Ansible-test on various stable branches does not yet work well with cgroups v2.
|
||||
# Since ubuntu-latest now uses Ubuntu 22.04, we need to fall back to the ubuntu-20.04
|
||||
# image for these stable branches. The list of branches where this is necessary will
|
||||
# shrink over time, check out https://github.com/ansible-collections/news-for-maintainers/issues/28
|
||||
# for the latest list.
|
||||
runs-on: ubuntu-latest
|
||||
name: EOL Units (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }})
|
||||
strategy:
|
||||
@@ -57,12 +67,12 @@ jobs:
|
||||
exclude:
|
||||
- ansible: ''
|
||||
include:
|
||||
- ansible: '2.16'
|
||||
- ansible: '2.15'
|
||||
python: '2.7'
|
||||
- ansible: '2.16'
|
||||
python: '3.6'
|
||||
- ansible: '2.16'
|
||||
python: '3.11'
|
||||
- ansible: '2.15'
|
||||
python: '3.5'
|
||||
- ansible: '2.15'
|
||||
python: '3.10'
|
||||
|
||||
steps:
|
||||
- name: >-
|
||||
@@ -82,6 +92,11 @@ jobs:
|
||||
testing-type: units
|
||||
|
||||
integration:
|
||||
# Ansible-test on various stable branches does not yet work well with cgroups v2.
|
||||
# Since ubuntu-latest now uses Ubuntu 22.04, we need to fall back to the ubuntu-20.04
|
||||
# image for these stable branches. The list of branches where this is necessary will
|
||||
# shrink over time, check out https://github.com/ansible-collections/news-for-maintainers/issues/28
|
||||
# for the latest list.
|
||||
runs-on: ubuntu-latest
|
||||
name: EOL I (Ⓐ${{ matrix.ansible }}+${{ matrix.docker }}+py${{ matrix.python }}:${{ matrix.target }})
|
||||
strategy:
|
||||
@@ -98,56 +113,43 @@ jobs:
|
||||
exclude:
|
||||
- ansible: ''
|
||||
include:
|
||||
# 2.16
|
||||
# CentOS 7 does not work in GHA, that's why it's not listed here.
|
||||
- ansible: '2.16'
|
||||
docker: fedora38
|
||||
# 2.15
|
||||
- ansible: '2.15'
|
||||
docker: alpine3
|
||||
python: ''
|
||||
target: azp/posix/1/
|
||||
- ansible: '2.16'
|
||||
docker: fedora38
|
||||
- ansible: '2.15'
|
||||
docker: alpine3
|
||||
python: ''
|
||||
target: azp/posix/2/
|
||||
- ansible: '2.16'
|
||||
docker: fedora38
|
||||
- ansible: '2.15'
|
||||
docker: alpine3
|
||||
python: ''
|
||||
target: azp/posix/3/
|
||||
- ansible: '2.16'
|
||||
docker: opensuse15
|
||||
- ansible: '2.15'
|
||||
docker: fedora37
|
||||
python: ''
|
||||
target: azp/posix/1/
|
||||
- ansible: '2.16'
|
||||
docker: opensuse15
|
||||
- ansible: '2.15'
|
||||
docker: fedora37
|
||||
python: ''
|
||||
target: azp/posix/2/
|
||||
- ansible: '2.16'
|
||||
docker: opensuse15
|
||||
python: ''
|
||||
target: azp/posix/3/
|
||||
- ansible: '2.16'
|
||||
docker: alpine3
|
||||
python: ''
|
||||
target: azp/posix/1/
|
||||
- ansible: '2.16'
|
||||
docker: alpine3
|
||||
python: ''
|
||||
target: azp/posix/2/
|
||||
- ansible: '2.16'
|
||||
docker: alpine3
|
||||
- ansible: '2.15'
|
||||
docker: fedora37
|
||||
python: ''
|
||||
target: azp/posix/3/
|
||||
# Right now all generic tests are disabled. Uncomment when at least one of them is re-enabled.
|
||||
# - ansible: '2.16'
|
||||
# - ansible: '2.13'
|
||||
# docker: default
|
||||
# python: '2.7'
|
||||
# python: '3.9'
|
||||
# target: azp/generic/1/
|
||||
# - ansible: '2.16'
|
||||
# - ansible: '2.14'
|
||||
# docker: default
|
||||
# python: '3.6'
|
||||
# python: '3.10'
|
||||
# target: azp/generic/1/
|
||||
# - ansible: '2.16'
|
||||
# - ansible: '2.15'
|
||||
# docker: default
|
||||
# python: '3.11'
|
||||
# python: '3.9'
|
||||
# target: azp/generic/1/
|
||||
|
||||
steps:
|
||||
|
||||
1554
CHANGELOG.md
1554
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
1458
CHANGELOG.rst
1458
CHANGELOG.rst
File diff suppressed because it is too large
Load Diff
16
README.md
16
README.md
@@ -6,10 +6,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# Community General Collection
|
||||
|
||||
[](https://docs.ansible.com/ansible/devel/collections/community/general/)
|
||||
[](https://dev.azure.com/ansible/community.general/_build?definitionId=31)
|
||||
[](https://github.com/ansible-collections/community.general/actions)
|
||||
[](https://github.com/ansible-collections/community.general/actions)
|
||||
[](https://docs.ansible.com/ansible/latest/collections/community/general/)
|
||||
[](https://dev.azure.com/ansible/community.general/_build?definitionId=31)
|
||||
[](https://github.com/ansible-collections/community.general/actions)
|
||||
[](https://github.com/ansible-collections/community.general/actions)
|
||||
[](https://codecov.io/gh/ansible-collections/community.general)
|
||||
[](https://api.reuse.software/info/github.com/ansible-collections/community.general)
|
||||
|
||||
@@ -39,7 +39,7 @@ For more information about communication, see the [Ansible communication guide](
|
||||
|
||||
## Tested with Ansible
|
||||
|
||||
Tested with the current ansible-core 2.16, ansible-core 2.17, ansible-core 2.18 releases and the current development version of ansible-core. Ansible-core versions before 2.16.0 are not supported. This includes all ansible-base 2.10 and Ansible 2.9 releases.
|
||||
Tested with the current ansible-core 2.15, ansible-core 2.16, ansible-core 2.17, ansible-core 2.18, ansible-core 2.19 releases and the current development version of ansible-core. Ansible-core versions before 2.15.0 are not supported. This includes all ansible-base 2.10 and Ansible 2.9 releases.
|
||||
|
||||
## External requirements
|
||||
|
||||
@@ -118,7 +118,7 @@ See the [Releasing guidelines](https://github.com/ansible/community-docs/blob/ma
|
||||
|
||||
## Release notes
|
||||
|
||||
See the [changelog](https://github.com/ansible-collections/community.general/blob/stable-11/CHANGELOG.md).
|
||||
See the [changelog](https://github.com/ansible-collections/community.general/blob/stable-10/CHANGELOG.md).
|
||||
|
||||
## Roadmap
|
||||
|
||||
@@ -137,8 +137,8 @@ See [this issue](https://github.com/ansible-collections/community.general/issues
|
||||
|
||||
This collection is primarily licensed and distributed as a whole under the GNU General Public License v3.0 or later.
|
||||
|
||||
See [LICENSES/GPL-3.0-or-later.txt](https://github.com/ansible-collections/community.general/blob/stable-11/COPYING) for the full text.
|
||||
See [LICENSES/GPL-3.0-or-later.txt](https://github.com/ansible-collections/community.general/blob/stable-10/COPYING) for the full text.
|
||||
|
||||
Parts of the collection are licensed under the [BSD 2-Clause license](https://github.com/ansible-collections/community.general/blob/stable-11/LICENSES/BSD-2-Clause.txt), the [MIT license](https://github.com/ansible-collections/community.general/blob/stable-11/LICENSES/MIT.txt), and the [PSF 2.0 license](https://github.com/ansible-collections/community.general/blob/stable-11/LICENSES/PSF-2.0.txt).
|
||||
Parts of the collection are licensed under the [BSD 2-Clause license](https://github.com/ansible-collections/community.general/blob/stable-10/LICENSES/BSD-2-Clause.txt), the [MIT license](https://github.com/ansible-collections/community.general/blob/stable-10/LICENSES/MIT.txt), and the [PSF 2.0 license](https://github.com/ansible-collections/community.general/blob/stable-10/LICENSES/PSF-2.0.txt).
|
||||
|
||||
All files have a machine readable `SDPX-License-Identifier:` comment denoting its respective license(s) or an equivalent entry in an accompanying `.license` file. Only changelog fragments (which will not be part of a release) are covered by a blanket statement in `REUSE.toml`. This conforms to the [REUSE specification](https://reuse.software/spec/).
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
"community.docker" = "git+https://github.com/ansible-collections/community.docker.git,main"
|
||||
"community.internal_test_tools" = "git+https://github.com/ansible-collections/community.internal_test_tools.git,main"
|
||||
|
||||
[collection_sources_per_ansible.'2.15']
|
||||
# community.crypto's main branch needs ansible-core >= 2.17
|
||||
"community.crypto" = "git+https://github.com/ansible-collections/community.crypto.git,stable-2"
|
||||
|
||||
[collection_sources_per_ansible.'2.16']
|
||||
# community.crypto's main branch needs ansible-core >= 2.17
|
||||
"community.crypto" = "git+https://github.com/ansible-collections/community.crypto.git,stable-2"
|
||||
@@ -24,18 +28,6 @@ run_no_unwanted_files = true
|
||||
no_unwanted_files_module_extensions = [".py"]
|
||||
no_unwanted_files_yaml_extensions = [".yml"]
|
||||
run_action_groups = true
|
||||
run_no_trailing_whitespace = true
|
||||
no_trailing_whitespace_skip_paths = [
|
||||
"tests/integration/targets/iso_extract/files/test.iso",
|
||||
"tests/integration/targets/java_cert/files/testpkcs.p12",
|
||||
"tests/integration/targets/one_host/files/testhost/tmp/opennebula-fixtures.json.gz",
|
||||
"tests/integration/targets/one_template/files/testhost/tmp/opennebula-fixtures.json.gz",
|
||||
"tests/integration/targets/setup_flatpak_remote/files/repo.tar.xz",
|
||||
]
|
||||
no_trailing_whitespace_skip_directories = [
|
||||
"tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/",
|
||||
"tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/input/",
|
||||
]
|
||||
|
||||
[[sessions.extra_checks.action_groups_config]]
|
||||
name = "consul"
|
||||
@@ -54,6 +46,12 @@ exclusions = [
|
||||
]
|
||||
doc_fragment = "community.general.keycloak.actiongroup_keycloak"
|
||||
|
||||
[[sessions.extra_checks.action_groups_config]]
|
||||
name = "proxmox"
|
||||
pattern = "^proxmox(_.*)?$"
|
||||
exclusions = []
|
||||
doc_fragment = "community.general.proxmox.actiongroup_proxmox"
|
||||
|
||||
[sessions.build_import_check]
|
||||
run_galaxy_importer = true
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,7 +36,7 @@ gives
|
||||
|
||||
result:
|
||||
{{ tests.0.result | to_yaml(indent=2) | indent(5) }}
|
||||
|
||||
|
||||
.. versionadded:: 9.1.0
|
||||
|
||||
* The results of the below examples 1-5 are all the same:
|
||||
|
||||
@@ -36,7 +36,7 @@ gives
|
||||
|
||||
result:
|
||||
{{ tests.0.result | to_yaml(indent=2) | indent(5) }}
|
||||
|
||||
|
||||
.. versionadded:: 9.1.0
|
||||
|
||||
* The results of the below examples 1-5 are all the same:
|
||||
|
||||
@@ -37,7 +37,7 @@ gives
|
||||
|
||||
result:
|
||||
{{ tests.0.result | to_yaml(indent=2) | indent(5) }}
|
||||
|
||||
|
||||
.. versionadded:: 9.1.0
|
||||
|
||||
* The results of the below examples 1-3 are all the same:
|
||||
|
||||
@@ -44,7 +44,7 @@ gives
|
||||
- {k0_x0: A0, k1_x1: B0}
|
||||
- {k0_x0: A1, k1_x1: B1}
|
||||
|
||||
|
||||
|
||||
.. versionadded:: 9.1.0
|
||||
|
||||
* The results of the below examples 1-5 are all the same:
|
||||
|
||||
@@ -46,7 +46,7 @@ gives
|
||||
- k2_x2: [C1]
|
||||
k3_x3: bar
|
||||
|
||||
|
||||
|
||||
.. versionadded:: 9.1.0
|
||||
|
||||
* The results of the below examples 1-5 are all the same:
|
||||
|
||||
@@ -53,7 +53,7 @@ gives
|
||||
k2_x2: [C1]
|
||||
k3_x3: bar
|
||||
|
||||
|
||||
|
||||
.. versionadded:: 9.1.0
|
||||
|
||||
* The results of the below examples 1-3 are all the same:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
.. _ansible_collections.community.general.docsite.filter_guide.filter_guide_abstract_informations.lists_of_dicts:
|
||||
|
||||
|
||||
Lists of dictionaries
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
community.general Filter Guide
|
||||
==============================
|
||||
|
||||
The :ref:`community.general collection <plugins_in_community.general>` offers several useful filter plugins.
|
||||
The :anscollection:`community.general collection <community.general#collection>` offers several useful filter plugins.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
@@ -38,6 +38,7 @@ But bear in mind that it does not showcase all of MH's features:
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
use_old_vardict = False
|
||||
|
||||
def __run__(self):
|
||||
self.vars.original_message = ''
|
||||
@@ -83,6 +84,10 @@ section above, but there are more elements that will take part in it.
|
||||
|
||||
facts_name = None # used if generating facts, from parameters or otherwise
|
||||
|
||||
# transitional variables for the new VarDict implementation, see information below
|
||||
use_old_vardict = True
|
||||
mute_vardict_deprecation = False
|
||||
|
||||
module = dict(
|
||||
argument_spec=dict(...),
|
||||
# ...
|
||||
@@ -202,14 +207,28 @@ By using ``self.vars``, you get a central mechanism to access the parameters but
|
||||
As described in :ref:`ansible_collections.community.general.docsite.guide_vardict`, variables in ``VarDict`` have metadata associated to them.
|
||||
One of the attributes in that metadata marks the variable for output, and MH makes use of that to generate the module's return values.
|
||||
|
||||
.. note::
|
||||
.. important::
|
||||
|
||||
The ``VarDict`` class was introduced in community.general 7.1.0, as part of ``ModuleHelper`` itself.
|
||||
However, it has been factored out to become an utility on its own, described in :ref:`ansible_collections.community.general.docsite.guide_vardict`,
|
||||
and the older implementation was removed in community.general 11.0.0.
|
||||
The ``VarDict`` feature described was introduced in community.general 7.1.0, but there was a first
|
||||
implementation of it embedded within ``ModuleHelper``.
|
||||
That older implementation is now deprecated and will be removed in community.general 11.0.0.
|
||||
After community.general 7.1.0, MH modules generate a deprecation message about *using the old VarDict*.
|
||||
There are two ways to prevent that from happening:
|
||||
|
||||
Some code might still refer to the class variables ``use_old_vardict`` and ``mute_vardict_deprecation``, used for the transtition to the new
|
||||
implementation but from community.general 11.0.0 onwards they are no longer used and can be safely removed from the code.
|
||||
#. Set ``mute_vardict_deprecation = True`` and the deprecation will be silenced. If the module still uses the old ``VarDict``,
|
||||
it will not be able to update to community.general 11.0.0 (Spring 2025) upon its release.
|
||||
#. Set ``use_old_vardict = False`` to make the MH module use the new ``VarDict`` immediately.
|
||||
We strongly recommend you use the new ``VarDict``, for that you make sure to consult its documentation at
|
||||
:ref:`ansible_collections.community.general.docsite.guide_vardict`.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
class MyTest(ModuleHelper):
|
||||
use_old_vardict = False
|
||||
mute_vardict_deprecation = True
|
||||
...
|
||||
|
||||
These two settings are mutually exclusive, but that is not enforced and the behavior when setting both is not specified.
|
||||
|
||||
Contrary to new variables created in ``VarDict``, module parameters are not set for output by default.
|
||||
If you want to include some module parameters in the output, list them in the ``output_params`` class variable.
|
||||
@@ -391,6 +410,7 @@ By using ``StateModuleHelper`` you can make your code like the excerpt from the
|
||||
module = dict(
|
||||
...
|
||||
)
|
||||
use_old_vardict = False
|
||||
|
||||
def __init_module__(self):
|
||||
self.runner = gconftool2_runner(self.module, check_rc=True)
|
||||
|
||||
@@ -51,7 +51,7 @@ And by the time the module is about to exit:
|
||||
|
||||
That makes the return value of the module:
|
||||
|
||||
.. code-block:: javascript
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"abc": 123,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
community.general Test (Plugin) Guide
|
||||
=====================================
|
||||
|
||||
The :ref:`community.general collection <plugins_in_community.general>` offers currently one test plugin.
|
||||
The :anscollection:`community.general collection <community.general#collection>` offers currently one test plugin.
|
||||
|
||||
.. contents:: Topics
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace: community
|
||||
name: general
|
||||
version: 11.0.0
|
||||
version: 10.7.2
|
||||
readme: README.md
|
||||
authors:
|
||||
- Ansible (https://github.com/ansible)
|
||||
|
||||
167
meta/runtime.yml
167
meta/runtime.yml
@@ -3,7 +3,7 @@
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
requires_ansible: '>=2.16.0'
|
||||
requires_ansible: '>=2.15.0'
|
||||
action_groups:
|
||||
consul:
|
||||
- consul_agent_check
|
||||
@@ -15,9 +15,24 @@ action_groups:
|
||||
- consul_session
|
||||
- consul_token
|
||||
proxmox:
|
||||
- metadata:
|
||||
extend_group:
|
||||
- community.proxmox.proxmox
|
||||
- proxmox
|
||||
- proxmox_backup
|
||||
- proxmox_backup_info
|
||||
- proxmox_disk
|
||||
- proxmox_domain_info
|
||||
- proxmox_group_info
|
||||
- proxmox_kvm
|
||||
- proxmox_nic
|
||||
- proxmox_node_info
|
||||
- proxmox_pool
|
||||
- proxmox_pool_member
|
||||
- proxmox_snap
|
||||
- proxmox_storage_contents_info
|
||||
- proxmox_storage_info
|
||||
- proxmox_tasks_info
|
||||
- proxmox_template
|
||||
- proxmox_user_info
|
||||
- proxmox_vm_info
|
||||
keycloak:
|
||||
- keycloak_authentication
|
||||
- keycloak_authentication_required_actions
|
||||
@@ -79,18 +94,13 @@ plugin_routing:
|
||||
redirect: community.docker.docker
|
||||
oc:
|
||||
redirect: community.okd.oc
|
||||
proxmox_pct_remote:
|
||||
redirect: community.proxmox.proxmox_pct_remote
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
lookup:
|
||||
gcp_storage_file:
|
||||
redirect: community.google.gcp_storage_file
|
||||
hashi_vault:
|
||||
redirect: community.hashi_vault.hashi_vault
|
||||
manifold:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: Company was acquired in 2021 and service was ceased afterwards.
|
||||
nios:
|
||||
@@ -119,39 +129,39 @@ plugin_routing:
|
||||
cisco_spark:
|
||||
redirect: community.general.cisco_webex
|
||||
clc_alert_policy:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: CenturyLink Cloud services went EOL in September 2023.
|
||||
clc_blueprint_package:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: CenturyLink Cloud services went EOL in September 2023.
|
||||
clc_firewall_policy:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: CenturyLink Cloud services went EOL in September 2023.
|
||||
clc_group:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: CenturyLink Cloud services went EOL in September 2023.
|
||||
clc_loadbalancer:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: CenturyLink Cloud services went EOL in September 2023.
|
||||
clc_modify_server:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: CenturyLink Cloud services went EOL in September 2023.
|
||||
clc_publicip:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: CenturyLink Cloud services went EOL in September 2023.
|
||||
clc_server:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: CenturyLink Cloud services went EOL in September 2023.
|
||||
clc_server_snapshot:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: CenturyLink Cloud services went EOL in September 2023.
|
||||
consul_acl:
|
||||
@@ -310,7 +320,7 @@ plugin_routing:
|
||||
hetzner_firewall_info:
|
||||
redirect: community.hrobot.firewall_info
|
||||
hipchat:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: The hipchat service has been discontinued and the self-hosted variant has been End of Life since 2020.
|
||||
hpilo_facts:
|
||||
@@ -635,115 +645,25 @@ plugin_routing:
|
||||
postgresql_user_obj_stat_info:
|
||||
redirect: community.postgresql.postgresql_user_obj_stat_info
|
||||
profitbricks:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: Supporting library is unsupported since 2021.
|
||||
profitbricks_datacenter:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: Supporting library is unsupported since 2021.
|
||||
profitbricks_nic:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: Supporting library is unsupported since 2021.
|
||||
profitbricks_volume:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: Supporting library is unsupported since 2021.
|
||||
profitbricks_volume_attachments:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: Supporting library is unsupported since 2021.
|
||||
proxmox:
|
||||
redirect: community.proxmox.proxmox
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_backup:
|
||||
redirect: community.proxmox.proxmox_backup
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_backup_info:
|
||||
redirect: community.proxmox.proxmox_backup_info
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_disk:
|
||||
redirect: community.proxmox.proxmox_disk
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_domain_info:
|
||||
redirect: community.proxmox.proxmox_domain_info
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_group_info:
|
||||
redirect: community.proxmox.proxmox_group_info
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_kvm:
|
||||
redirect: community.proxmox.proxmox_kvm
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_nic:
|
||||
redirect: community.proxmox.proxmox_nic
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_node_info:
|
||||
redirect: community.proxmox.proxmox_node_info
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_pool:
|
||||
redirect: community.proxmox.proxmox_pool
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_pool_member:
|
||||
redirect: community.proxmox.proxmox_pool_member
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_snap:
|
||||
redirect: community.proxmox.proxmox_snap
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_storage_contents_info:
|
||||
redirect: community.proxmox.proxmox_storage_contents_info
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_storage_info:
|
||||
redirect: community.proxmox.proxmox_storage_info
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_tasks_info:
|
||||
redirect: community.proxmox.proxmox_tasks_info
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_template:
|
||||
redirect: community.proxmox.proxmox_template
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_user_info:
|
||||
redirect: community.proxmox.proxmox_user_info
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
proxmox_vm_info:
|
||||
redirect: community.proxmox.proxmox_vm_info
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
purefa_facts:
|
||||
tombstone:
|
||||
removal_version: 3.0.0
|
||||
@@ -1002,11 +922,6 @@ plugin_routing:
|
||||
redirect: infoblox.nios_modules.nios
|
||||
postgresql:
|
||||
redirect: community.postgresql.postgresql
|
||||
proxmox:
|
||||
redirect: community.proxmox.proxmox
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
purestorage:
|
||||
deprecation:
|
||||
removal_version: 12.0.0
|
||||
@@ -1035,11 +950,6 @@ plugin_routing:
|
||||
redirect: infoblox.nios_modules.api
|
||||
postgresql:
|
||||
redirect: community.postgresql.postgresql
|
||||
proxmox:
|
||||
redirect: community.proxmox.proxmox
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
pure:
|
||||
deprecation:
|
||||
removal_version: 12.0.0
|
||||
@@ -1057,15 +967,10 @@ plugin_routing:
|
||||
redirect: community.docker.docker_machine
|
||||
docker_swarm:
|
||||
redirect: community.docker.docker_swarm
|
||||
proxmox:
|
||||
redirect: community.proxmox.proxmox
|
||||
deprecation:
|
||||
removal_version: 15.0.0
|
||||
warning_text: The proxmox content has been moved to community.proxmox.
|
||||
kubevirt:
|
||||
redirect: community.kubevirt.kubevirt
|
||||
stackpath_compute:
|
||||
tombstone:
|
||||
deprecation:
|
||||
removal_version: 11.0.0
|
||||
warning_text: The company and the service were sunset in June 2024.
|
||||
filter:
|
||||
|
||||
@@ -87,7 +87,6 @@ from contextlib import closing
|
||||
from os.path import basename
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleRuntimeError
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible.module_utils.six import raise_from
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
@@ -141,6 +140,7 @@ class HostData:
|
||||
class ElasticSource(object):
|
||||
def __init__(self, display):
|
||||
self.ansible_playbook = ""
|
||||
self.ansible_version = None
|
||||
self.session = str(uuid.uuid4())
|
||||
self.host = socket.gethostname()
|
||||
try:
|
||||
@@ -183,6 +183,9 @@ class ElasticSource(object):
|
||||
|
||||
task = tasks_data[task_uuid]
|
||||
|
||||
if self.ansible_version is None and result._task_fields['args'].get('_ansible_version'):
|
||||
self.ansible_version = result._task_fields['args'].get('_ansible_version')
|
||||
|
||||
task.add_host(HostData(host_uuid, host_name, status, result))
|
||||
|
||||
def generate_distributed_traces(self, tasks_data, status, end_time, traceparent, apm_service_name,
|
||||
@@ -206,7 +209,8 @@ class ElasticSource(object):
|
||||
else:
|
||||
apm_cli.begin_transaction("Session", start=parent_start_time)
|
||||
# Populate trace metadata attributes
|
||||
label(ansible_version=ansible_version)
|
||||
if self.ansible_version is not None:
|
||||
label(ansible_version=self.ansible_version)
|
||||
label(ansible_session=self.session, ansible_host_name=self.host, ansible_host_user=self.user)
|
||||
if self.ip_address is not None:
|
||||
label(ansible_host_ip=self.ip_address)
|
||||
|
||||
@@ -62,7 +62,6 @@ import getpass
|
||||
|
||||
from os.path import basename
|
||||
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.parsing.ajson import AnsibleJSONEncoder
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
@@ -76,6 +75,7 @@ class AzureLogAnalyticsSource(object):
|
||||
def __init__(self):
|
||||
self.ansible_check_mode = False
|
||||
self.ansible_playbook = ""
|
||||
self.ansible_version = ""
|
||||
self.session = str(uuid.uuid4())
|
||||
self.host = socket.gethostname()
|
||||
self.user = getpass.getuser()
|
||||
@@ -102,6 +102,10 @@ class AzureLogAnalyticsSource(object):
|
||||
if result._task_fields['args'].get('_ansible_check_mode') is True:
|
||||
self.ansible_check_mode = True
|
||||
|
||||
if result._task_fields['args'].get('_ansible_version'):
|
||||
self.ansible_version = \
|
||||
result._task_fields['args'].get('_ansible_version')
|
||||
|
||||
if result._task._role:
|
||||
ansible_role = str(result._task._role)
|
||||
else:
|
||||
@@ -115,7 +119,7 @@ class AzureLogAnalyticsSource(object):
|
||||
data['host'] = self.host
|
||||
data['user'] = self.user
|
||||
data['runtime'] = runtime
|
||||
data['ansible_version'] = ansible_version
|
||||
data['ansible_version'] = self.ansible_version
|
||||
data['ansible_check_mode'] = self.ansible_check_mode
|
||||
data['ansible_host'] = result._host.name
|
||||
data['ansible_playbook'] = self.ansible_playbook
|
||||
|
||||
@@ -127,9 +127,7 @@ class CallbackModule(CallbackBase):
|
||||
|
||||
if not HAS_LOGSTASH:
|
||||
self.disabled = True
|
||||
self._display.warning("The required python-logstash/python3-logstash is not installed. "
|
||||
"pip install python-logstash for Python 2"
|
||||
"pip install python3-logstash for Python 3")
|
||||
self._display.warning("The required python3-logstash is not installed.")
|
||||
|
||||
self.start_time = now()
|
||||
|
||||
|
||||
@@ -143,7 +143,6 @@ from collections import OrderedDict
|
||||
from os.path import basename
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible.module_utils.six import raise_from
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
@@ -213,6 +212,7 @@ class HostData:
|
||||
class OpenTelemetrySource(object):
|
||||
def __init__(self, display):
|
||||
self.ansible_playbook = ""
|
||||
self.ansible_version = None
|
||||
self.session = str(uuid.uuid4())
|
||||
self.host = socket.gethostname()
|
||||
try:
|
||||
@@ -260,6 +260,9 @@ class OpenTelemetrySource(object):
|
||||
|
||||
task = tasks_data[task_uuid]
|
||||
|
||||
if self.ansible_version is None and hasattr(result, '_task_fields') and result._task_fields['args'].get('_ansible_version'):
|
||||
self.ansible_version = result._task_fields['args'].get('_ansible_version')
|
||||
|
||||
task.dump = dump
|
||||
task.add_host(HostData(host_uuid, host_name, status, result))
|
||||
|
||||
@@ -307,7 +310,8 @@ class OpenTelemetrySource(object):
|
||||
start_time=parent_start_time, kind=SpanKind.SERVER) as parent:
|
||||
parent.set_status(status)
|
||||
# Populate trace metadata attributes
|
||||
parent.set_attribute("ansible.version", ansible_version)
|
||||
if self.ansible_version is not None:
|
||||
parent.set_attribute("ansible.version", self.ansible_version)
|
||||
parent.set_attribute("ansible.session", self.session)
|
||||
parent.set_attribute("ansible.host.name", self.host)
|
||||
if self.ip_address is not None:
|
||||
|
||||
@@ -91,7 +91,6 @@ import getpass
|
||||
|
||||
from os.path import basename
|
||||
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.parsing.ajson import AnsibleJSONEncoder
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
@@ -105,6 +104,7 @@ class SplunkHTTPCollectorSource(object):
|
||||
def __init__(self):
|
||||
self.ansible_check_mode = False
|
||||
self.ansible_playbook = ""
|
||||
self.ansible_version = ""
|
||||
self.session = str(uuid.uuid4())
|
||||
self.host = socket.gethostname()
|
||||
self.ip_address = socket.gethostbyname(socket.gethostname())
|
||||
@@ -114,6 +114,10 @@ class SplunkHTTPCollectorSource(object):
|
||||
if result._task_fields['args'].get('_ansible_check_mode') is True:
|
||||
self.ansible_check_mode = True
|
||||
|
||||
if result._task_fields['args'].get('_ansible_version'):
|
||||
self.ansible_version = \
|
||||
result._task_fields['args'].get('_ansible_version')
|
||||
|
||||
if result._task._role:
|
||||
ansible_role = str(result._task._role)
|
||||
else:
|
||||
@@ -139,7 +143,7 @@ class SplunkHTTPCollectorSource(object):
|
||||
data['ip_address'] = self.ip_address
|
||||
data['user'] = self.user
|
||||
data['runtime'] = runtime
|
||||
data['ansible_version'] = ansible_version
|
||||
data['ansible_version'] = self.ansible_version
|
||||
data['ansible_check_mode'] = self.ansible_check_mode
|
||||
data['ansible_host'] = result._host.name
|
||||
data['ansible_playbook'] = self.ansible_playbook
|
||||
|
||||
@@ -48,7 +48,6 @@ import getpass
|
||||
|
||||
from os.path import basename
|
||||
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.parsing.ajson import AnsibleJSONEncoder
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
@@ -62,6 +61,7 @@ class SumologicHTTPCollectorSource(object):
|
||||
def __init__(self):
|
||||
self.ansible_check_mode = False
|
||||
self.ansible_playbook = ""
|
||||
self.ansible_version = ""
|
||||
self.session = str(uuid.uuid4())
|
||||
self.host = socket.gethostname()
|
||||
self.ip_address = socket.gethostbyname(socket.gethostname())
|
||||
@@ -71,6 +71,10 @@ class SumologicHTTPCollectorSource(object):
|
||||
if result._task_fields['args'].get('_ansible_check_mode') is True:
|
||||
self.ansible_check_mode = True
|
||||
|
||||
if result._task_fields['args'].get('_ansible_version'):
|
||||
self.ansible_version = \
|
||||
result._task_fields['args'].get('_ansible_version')
|
||||
|
||||
if result._task._role:
|
||||
ansible_role = str(result._task._role)
|
||||
else:
|
||||
@@ -88,7 +92,7 @@ class SumologicHTTPCollectorSource(object):
|
||||
data['ip_address'] = self.ip_address
|
||||
data['user'] = self.user
|
||||
data['runtime'] = runtime
|
||||
data['ansible_version'] = ansible_version
|
||||
data['ansible_version'] = self.ansible_version
|
||||
data['ansible_check_mode'] = self.ansible_check_mode
|
||||
data['ansible_host'] = result._host.name
|
||||
data['ansible_playbook'] = self.ansible_playbook
|
||||
|
||||
@@ -155,11 +155,35 @@ class Connection(ConnectionBase):
|
||||
stdout = to_text(stdout)
|
||||
stderr = to_text(stderr)
|
||||
|
||||
if stderr == "Error: Instance is not running.\n":
|
||||
raise AnsibleConnectionFailure(f"instance not running: {self._instance()}")
|
||||
if stderr.startswith("Error: ") and stderr.rstrip().endswith(
|
||||
": Instance is not running"
|
||||
):
|
||||
raise AnsibleConnectionFailure(
|
||||
f"instance not running: {self._instance()} (remote={self.get_option('remote')}, project={self.get_option('project')})"
|
||||
)
|
||||
|
||||
if stderr == "Error: Instance not found\n":
|
||||
raise AnsibleConnectionFailure(f"instance not found: {self._instance()}")
|
||||
if stderr.startswith("Error: ") and stderr.rstrip().endswith(
|
||||
": Instance not found"
|
||||
):
|
||||
raise AnsibleConnectionFailure(
|
||||
f"instance not found: {self._instance()} (remote={self.get_option('remote')}, project={self.get_option('project')})"
|
||||
)
|
||||
|
||||
if (
|
||||
stderr.startswith("Error: ")
|
||||
and ": User does not have permission " in stderr
|
||||
):
|
||||
raise AnsibleConnectionFailure(
|
||||
f"instance access denied: {self._instance()} (remote={self.get_option('remote')}, project={self.get_option('project')})"
|
||||
)
|
||||
|
||||
if (
|
||||
stderr.startswith("Error: ")
|
||||
and ": User does not have entitlement " in stderr
|
||||
):
|
||||
raise AnsibleConnectionFailure(
|
||||
f"instance access denied: {self._instance()} (remote={self.get_option('remote')}, project={self.get_option('project')})"
|
||||
)
|
||||
|
||||
return process.returncode, stdout, stderr
|
||||
|
||||
|
||||
857
plugins/connection/proxmox_pct_remote.py
Normal file
857
plugins/connection/proxmox_pct_remote.py
Normal file
@@ -0,0 +1,857 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Derived from ansible/plugins/connection/paramiko_ssh.py (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
||||
# Copyright (c) 2024 Nils Stein (@mietzen) <github.nstein@mailbox.org>
|
||||
# Copyright (c) 2024 Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
author: Nils Stein (@mietzen) <github.nstein@mailbox.org>
|
||||
name: proxmox_pct_remote
|
||||
short_description: Run tasks in Proxmox LXC container instances using pct CLI via SSH
|
||||
requirements:
|
||||
- paramiko
|
||||
description:
|
||||
- Run commands or put/fetch files to an existing Proxmox LXC container using pct CLI via SSH.
|
||||
- Uses the Python SSH implementation (Paramiko) to connect to the Proxmox host.
|
||||
version_added: "10.3.0"
|
||||
options:
|
||||
remote_addr:
|
||||
description:
|
||||
- Address of the remote target.
|
||||
default: inventory_hostname
|
||||
type: string
|
||||
vars:
|
||||
- name: inventory_hostname
|
||||
- name: ansible_host
|
||||
- name: ansible_ssh_host
|
||||
- name: ansible_paramiko_host
|
||||
port:
|
||||
description: Remote port to connect to.
|
||||
type: int
|
||||
default: 22
|
||||
ini:
|
||||
- section: defaults
|
||||
key: remote_port
|
||||
- section: paramiko_connection
|
||||
key: remote_port
|
||||
env:
|
||||
- name: ANSIBLE_REMOTE_PORT
|
||||
- name: ANSIBLE_REMOTE_PARAMIKO_PORT
|
||||
vars:
|
||||
- name: ansible_port
|
||||
- name: ansible_ssh_port
|
||||
- name: ansible_paramiko_port
|
||||
keyword:
|
||||
- name: port
|
||||
remote_user:
|
||||
description:
|
||||
- User to login/authenticate as.
|
||||
- Can be set from the CLI via the C(--user) or C(-u) options.
|
||||
type: string
|
||||
vars:
|
||||
- name: ansible_user
|
||||
- name: ansible_ssh_user
|
||||
- name: ansible_paramiko_user
|
||||
env:
|
||||
- name: ANSIBLE_REMOTE_USER
|
||||
- name: ANSIBLE_PARAMIKO_REMOTE_USER
|
||||
ini:
|
||||
- section: defaults
|
||||
key: remote_user
|
||||
- section: paramiko_connection
|
||||
key: remote_user
|
||||
keyword:
|
||||
- name: remote_user
|
||||
password:
|
||||
description:
|
||||
- Secret used to either login the SSH server or as a passphrase for SSH keys that require it.
|
||||
- Can be set from the CLI via the C(--ask-pass) option.
|
||||
type: string
|
||||
vars:
|
||||
- name: ansible_password
|
||||
- name: ansible_ssh_pass
|
||||
- name: ansible_ssh_password
|
||||
- name: ansible_paramiko_pass
|
||||
- name: ansible_paramiko_password
|
||||
use_rsa_sha2_algorithms:
|
||||
description:
|
||||
- Whether or not to enable RSA SHA2 algorithms for pubkeys and hostkeys.
|
||||
- On paramiko versions older than 2.9, this only affects hostkeys.
|
||||
- For behavior matching paramiko<2.9 set this to V(false).
|
||||
vars:
|
||||
- name: ansible_paramiko_use_rsa_sha2_algorithms
|
||||
ini:
|
||||
- {key: use_rsa_sha2_algorithms, section: paramiko_connection}
|
||||
env:
|
||||
- {name: ANSIBLE_PARAMIKO_USE_RSA_SHA2_ALGORITHMS}
|
||||
default: true
|
||||
type: boolean
|
||||
host_key_auto_add:
|
||||
description: "Automatically add host keys to C(~/.ssh/known_hosts)."
|
||||
env:
|
||||
- name: ANSIBLE_PARAMIKO_HOST_KEY_AUTO_ADD
|
||||
ini:
|
||||
- key: host_key_auto_add
|
||||
section: paramiko_connection
|
||||
type: boolean
|
||||
look_for_keys:
|
||||
default: True
|
||||
description: "Set to V(false) to disable searching for private key files in C(~/.ssh/)."
|
||||
env:
|
||||
- name: ANSIBLE_PARAMIKO_LOOK_FOR_KEYS
|
||||
ini:
|
||||
- {key: look_for_keys, section: paramiko_connection}
|
||||
type: boolean
|
||||
proxy_command:
|
||||
default: ""
|
||||
description:
|
||||
- Proxy information for running the connection via a jumphost.
|
||||
type: string
|
||||
env:
|
||||
- name: ANSIBLE_PARAMIKO_PROXY_COMMAND
|
||||
ini:
|
||||
- {key: proxy_command, section: paramiko_connection}
|
||||
vars:
|
||||
- name: ansible_paramiko_proxy_command
|
||||
pty:
|
||||
default: True
|
||||
description: "C(sudo) usually requires a PTY, V(true) to give a PTY and V(false) to not give a PTY."
|
||||
env:
|
||||
- name: ANSIBLE_PARAMIKO_PTY
|
||||
ini:
|
||||
- section: paramiko_connection
|
||||
key: pty
|
||||
type: boolean
|
||||
record_host_keys:
|
||||
default: True
|
||||
description: "Save the host keys to a file."
|
||||
env:
|
||||
- name: ANSIBLE_PARAMIKO_RECORD_HOST_KEYS
|
||||
ini:
|
||||
- section: paramiko_connection
|
||||
key: record_host_keys
|
||||
type: boolean
|
||||
host_key_checking:
|
||||
description: "Set this to V(false) if you want to avoid host key checking by the underlying tools Ansible uses to connect to the host."
|
||||
type: boolean
|
||||
default: true
|
||||
env:
|
||||
- name: ANSIBLE_HOST_KEY_CHECKING
|
||||
- name: ANSIBLE_SSH_HOST_KEY_CHECKING
|
||||
- name: ANSIBLE_PARAMIKO_HOST_KEY_CHECKING
|
||||
ini:
|
||||
- section: defaults
|
||||
key: host_key_checking
|
||||
- section: paramiko_connection
|
||||
key: host_key_checking
|
||||
vars:
|
||||
- name: ansible_host_key_checking
|
||||
- name: ansible_ssh_host_key_checking
|
||||
- name: ansible_paramiko_host_key_checking
|
||||
use_persistent_connections:
|
||||
description: "Toggles the use of persistence for connections."
|
||||
type: boolean
|
||||
default: False
|
||||
env:
|
||||
- name: ANSIBLE_USE_PERSISTENT_CONNECTIONS
|
||||
ini:
|
||||
- section: defaults
|
||||
key: use_persistent_connections
|
||||
banner_timeout:
|
||||
type: float
|
||||
default: 30
|
||||
description:
|
||||
- Configures, in seconds, the amount of time to wait for the SSH
|
||||
banner to be presented. This option is supported by paramiko
|
||||
version 1.15.0 or newer.
|
||||
ini:
|
||||
- section: paramiko_connection
|
||||
key: banner_timeout
|
||||
env:
|
||||
- name: ANSIBLE_PARAMIKO_BANNER_TIMEOUT
|
||||
timeout:
|
||||
type: int
|
||||
default: 10
|
||||
description: Number of seconds until the plugin gives up on failing to establish a TCP connection.
|
||||
ini:
|
||||
- section: defaults
|
||||
key: timeout
|
||||
- section: ssh_connection
|
||||
key: timeout
|
||||
- section: paramiko_connection
|
||||
key: timeout
|
||||
env:
|
||||
- name: ANSIBLE_TIMEOUT
|
||||
- name: ANSIBLE_SSH_TIMEOUT
|
||||
- name: ANSIBLE_PARAMIKO_TIMEOUT
|
||||
vars:
|
||||
- name: ansible_ssh_timeout
|
||||
- name: ansible_paramiko_timeout
|
||||
cli:
|
||||
- name: timeout
|
||||
lock_file_timeout:
|
||||
type: int
|
||||
default: 60
|
||||
description: Number of seconds until the plugin gives up on trying to write a lock file when writing SSH known host keys.
|
||||
vars:
|
||||
- name: ansible_lock_file_timeout
|
||||
env:
|
||||
- name: ANSIBLE_LOCK_FILE_TIMEOUT
|
||||
private_key_file:
|
||||
description:
|
||||
- Path to private key file to use for authentication.
|
||||
type: string
|
||||
ini:
|
||||
- section: defaults
|
||||
key: private_key_file
|
||||
- section: paramiko_connection
|
||||
key: private_key_file
|
||||
env:
|
||||
- name: ANSIBLE_PRIVATE_KEY_FILE
|
||||
- name: ANSIBLE_PARAMIKO_PRIVATE_KEY_FILE
|
||||
vars:
|
||||
- name: ansible_private_key_file
|
||||
- name: ansible_ssh_private_key_file
|
||||
- name: ansible_paramiko_private_key_file
|
||||
cli:
|
||||
- name: private_key_file
|
||||
option: "--private-key"
|
||||
vmid:
|
||||
description:
|
||||
- LXC Container ID
|
||||
type: int
|
||||
vars:
|
||||
- name: proxmox_vmid
|
||||
proxmox_become_method:
|
||||
description:
|
||||
- Become command used in proxmox
|
||||
type: str
|
||||
default: sudo
|
||||
vars:
|
||||
- name: proxmox_become_method
|
||||
notes:
|
||||
- >
|
||||
When NOT using this plugin as root, you need to have a become mechanism,
|
||||
e.g. C(sudo), installed on Proxmox and setup so we can run it without prompting for the password.
|
||||
Inside the container, we need a shell, for example C(sh) and the C(cat) command to be available in the C(PATH) for this plugin to work.
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
# --------------------------------------------------------------
|
||||
# Setup sudo with password less access to pct for user 'ansible':
|
||||
# --------------------------------------------------------------
|
||||
#
|
||||
# Open a Proxmox root shell and execute:
|
||||
# $ useradd -d /opt/ansible-pct -r -m -s /bin/sh ansible
|
||||
# $ mkdir -p /opt/ansible-pct/.ssh
|
||||
# $ ssh-keygen -t ed25519 -C 'ansible' -N "" -f /opt/ansible-pct/.ssh/ansible <<< y > /dev/null
|
||||
# $ cat /opt/ansible-pct/.ssh/ansible
|
||||
# $ mv /opt/ansible-pct/.ssh/ansible.pub /opt/ansible-pct/.ssh/authorized-keys
|
||||
# $ rm /opt/ansible-pct/.ssh/ansible*
|
||||
# $ chown -R ansible:ansible /opt/ansible-pct/.ssh
|
||||
# $ chmod 700 /opt/ansible-pct/.ssh
|
||||
# $ chmod 600 /opt/ansible-pct/.ssh/authorized-keys
|
||||
# $ echo 'ansible ALL = (root) NOPASSWD: /usr/sbin/pct' > /etc/sudoers.d/ansible_pct
|
||||
#
|
||||
# Save the displayed private key and add it to your ssh-agent
|
||||
#
|
||||
# Or use ansible:
|
||||
# ---
|
||||
# - name: Setup ansible-pct user and configure environment on Proxmox host
|
||||
# hosts: proxmox
|
||||
# become: true
|
||||
# gather_facts: false
|
||||
#
|
||||
# tasks:
|
||||
# - name: Create ansible user
|
||||
# ansible.builtin.user:
|
||||
# name: ansible
|
||||
# comment: Ansible User
|
||||
# home: /opt/ansible-pct
|
||||
# shell: /bin/sh
|
||||
# create_home: true
|
||||
# system: true
|
||||
#
|
||||
# - name: Create .ssh directory
|
||||
# ansible.builtin.file:
|
||||
# path: /opt/ansible-pct/.ssh
|
||||
# state: directory
|
||||
# owner: ansible
|
||||
# group: ansible
|
||||
# mode: '0700'
|
||||
#
|
||||
# - name: Generate SSH key for ansible user
|
||||
# community.crypto.openssh_keypair:
|
||||
# path: /opt/ansible-pct/.ssh/ansible
|
||||
# type: ed25519
|
||||
# comment: 'ansible'
|
||||
# force: true
|
||||
# mode: '0600'
|
||||
# owner: ansible
|
||||
# group: ansible
|
||||
#
|
||||
# - name: Set public key as authorized key
|
||||
# ansible.builtin.copy:
|
||||
# src: /opt/ansible-pct/.ssh/ansible.pub
|
||||
# dest: /opt/ansible-pct/.ssh/authorized-keys
|
||||
# remote_src: yes
|
||||
# owner: ansible
|
||||
# group: ansible
|
||||
# mode: '0600'
|
||||
#
|
||||
# - name: Add sudoers entry for ansible user
|
||||
# ansible.builtin.copy:
|
||||
# content: 'ansible ALL = (root) NOPASSWD: /usr/sbin/pct'
|
||||
# dest: /etc/sudoers.d/ansible_pct
|
||||
# owner: root
|
||||
# group: root
|
||||
# mode: '0440'
|
||||
#
|
||||
# - name: Fetch private SSH key to localhost
|
||||
# ansible.builtin.fetch:
|
||||
# src: /opt/ansible-pct/.ssh/ansible
|
||||
# dest: ~/.ssh/proxmox_ansible_private_key
|
||||
# flat: yes
|
||||
# fail_on_missing: true
|
||||
#
|
||||
# - name: Clean up generated SSH keys
|
||||
# ansible.builtin.file:
|
||||
# path: /opt/ansible-pct/.ssh/ansible*
|
||||
# state: absent
|
||||
#
|
||||
# - name: Configure private key permissions on localhost
|
||||
# hosts: localhost
|
||||
# tasks:
|
||||
# - name: Set permissions for fetched private key
|
||||
# ansible.builtin.file:
|
||||
# path: ~/.ssh/proxmox_ansible_private_key
|
||||
# mode: '0600'
|
||||
#
|
||||
# --------------------------------
|
||||
# Static inventory file: hosts.yml
|
||||
# --------------------------------
|
||||
# all:
|
||||
# children:
|
||||
# lxc:
|
||||
# hosts:
|
||||
# container-1:
|
||||
# ansible_host: 10.0.0.10
|
||||
# proxmox_vmid: 100
|
||||
# ansible_connection: community.general.proxmox_pct_remote
|
||||
# ansible_user: ansible
|
||||
# container-2:
|
||||
# ansible_host: 10.0.0.10
|
||||
# proxmox_vmid: 200
|
||||
# ansible_connection: community.general.proxmox_pct_remote
|
||||
# ansible_user: ansible
|
||||
# proxmox:
|
||||
# hosts:
|
||||
# proxmox-1:
|
||||
# ansible_host: 10.0.0.10
|
||||
#
|
||||
#
|
||||
# ---------------------------------------------
|
||||
# Dynamic inventory file: inventory.proxmox.yml
|
||||
# ---------------------------------------------
|
||||
# plugin: community.general.proxmox
|
||||
# url: https://10.0.0.10:8006
|
||||
# validate_certs: false
|
||||
# user: ansible@pam
|
||||
# token_id: ansible
|
||||
# token_secret: !vault |
|
||||
# $ANSIBLE_VAULT;1.1;AES256
|
||||
# ...
|
||||
|
||||
# want_facts: true
|
||||
# exclude_nodes: true
|
||||
# filters:
|
||||
# - proxmox_vmtype == "lxc"
|
||||
# want_proxmox_nodes_ansible_host: false
|
||||
# compose:
|
||||
# ansible_host: "'10.0.0.10'"
|
||||
# ansible_connection: "'community.general.proxmox_pct_remote'"
|
||||
# ansible_user: "'ansible'"
|
||||
#
|
||||
#
|
||||
# ----------------------
|
||||
# Playbook: playbook.yml
|
||||
# ----------------------
|
||||
---
|
||||
- hosts: lxc
|
||||
# On nodes with many containers you might want to deactivate the devices facts
|
||||
# or set `gather_facts: false` if you don't need them.
|
||||
# More info on gathering fact subsets:
|
||||
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module.html
|
||||
#
|
||||
# gather_facts: true
|
||||
# gather_subset:
|
||||
# - "!devices"
|
||||
tasks:
|
||||
- name: Ping LXC container
|
||||
ansible.builtin.ping:
|
||||
"""
|
||||
|
||||
import os
|
||||
import pathlib
|
||||
import socket
|
||||
import tempfile
|
||||
import typing as t
|
||||
|
||||
from ansible.errors import (
|
||||
AnsibleAuthenticationFailure,
|
||||
AnsibleConnectionFailure,
|
||||
AnsibleError,
|
||||
)
|
||||
from ansible_collections.community.general.plugins.module_utils._filelock import FileLock, LockTimeout
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
|
||||
from ansible.module_utils.compat.paramiko import PARAMIKO_IMPORT_ERR, paramiko
|
||||
from ansible.module_utils.compat.version import LooseVersion
|
||||
from ansible.plugins.connection import ConnectionBase
|
||||
from ansible.utils.display import Display
|
||||
from ansible.utils.path import makedirs_safe
|
||||
from binascii import hexlify
|
||||
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
def authenticity_msg(hostname: str, ktype: str, fingerprint: str) -> str:
|
||||
msg = f"""
|
||||
paramiko: The authenticity of host '{hostname}' can't be established.
|
||||
The {ktype} key fingerprint is {fingerprint}.
|
||||
Are you sure you want to continue connecting (yes/no)?
|
||||
"""
|
||||
return msg
|
||||
|
||||
|
||||
MissingHostKeyPolicy: type = object
|
||||
if paramiko:
|
||||
MissingHostKeyPolicy = paramiko.MissingHostKeyPolicy
|
||||
|
||||
|
||||
class MyAddPolicy(MissingHostKeyPolicy):
|
||||
"""
|
||||
Based on AutoAddPolicy in paramiko so we can determine when keys are added
|
||||
|
||||
and also prompt for input.
|
||||
|
||||
Policy for automatically adding the hostname and new host key to the
|
||||
local L{HostKeys} object, and saving it. This is used by L{SSHClient}.
|
||||
"""
|
||||
|
||||
def __init__(self, connection: Connection) -> None:
|
||||
self.connection = connection
|
||||
self._options = connection._options
|
||||
|
||||
def missing_host_key(self, client, hostname, key) -> None:
|
||||
|
||||
if all((self.connection.get_option('host_key_checking'), not self.connection.get_option('host_key_auto_add'))):
|
||||
|
||||
fingerprint = hexlify(key.get_fingerprint())
|
||||
ktype = key.get_name()
|
||||
|
||||
if self.connection.get_option('use_persistent_connections') or self.connection.force_persistence:
|
||||
# don't print the prompt string since the user cannot respond
|
||||
# to the question anyway
|
||||
raise AnsibleError(authenticity_msg(hostname, ktype, fingerprint)[1:92])
|
||||
|
||||
inp = to_text(
|
||||
display.prompt_until(authenticity_msg(hostname, ktype, fingerprint), private=False),
|
||||
errors='surrogate_or_strict'
|
||||
)
|
||||
|
||||
if inp.lower() not in ['yes', 'y', '']:
|
||||
raise AnsibleError('host connection rejected by user')
|
||||
|
||||
key._added_by_ansible_this_time = True
|
||||
|
||||
# existing implementation below:
|
||||
client._host_keys.add(hostname, key.get_name(), key)
|
||||
|
||||
# host keys are actually saved in close() function below
|
||||
# in order to control ordering.
|
||||
|
||||
|
||||
class Connection(ConnectionBase):
|
||||
""" SSH based connections (paramiko) to Proxmox pct """
|
||||
|
||||
transport = 'community.general.proxmox_pct_remote'
|
||||
_log_channel: str | None = None
|
||||
|
||||
def __init__(self, play_context, new_stdin, *args, **kwargs):
|
||||
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)
|
||||
|
||||
def _set_log_channel(self, name: str) -> None:
|
||||
""" Mimic paramiko.SSHClient.set_log_channel """
|
||||
self._log_channel = name
|
||||
|
||||
def _parse_proxy_command(self, port: int = 22) -> dict[str, t.Any]:
|
||||
proxy_command = self.get_option('proxy_command') or None
|
||||
|
||||
sock_kwarg = {}
|
||||
if proxy_command:
|
||||
replacers = {
|
||||
'%h': self.get_option('remote_addr'),
|
||||
'%p': port,
|
||||
'%r': self.get_option('remote_user')
|
||||
}
|
||||
for find, replace in replacers.items():
|
||||
proxy_command = proxy_command.replace(find, str(replace))
|
||||
try:
|
||||
sock_kwarg = {'sock': paramiko.ProxyCommand(proxy_command)}
|
||||
display.vvv(f'CONFIGURE PROXY COMMAND FOR CONNECTION: {proxy_command}', host=self.get_option('remote_addr'))
|
||||
except AttributeError:
|
||||
display.warning('Paramiko ProxyCommand support unavailable. '
|
||||
'Please upgrade to Paramiko 1.9.0 or newer. '
|
||||
'Not using configured ProxyCommand')
|
||||
|
||||
return sock_kwarg
|
||||
|
||||
def _connect(self) -> Connection:
|
||||
""" activates the connection object """
|
||||
|
||||
if paramiko is None:
|
||||
raise AnsibleError(f'paramiko is not installed: {to_native(PARAMIKO_IMPORT_ERR)}')
|
||||
|
||||
port = self.get_option('port')
|
||||
display.vvv(f'ESTABLISH PARAMIKO SSH CONNECTION FOR USER: {self.get_option("remote_user")} on PORT {to_text(port)} TO {self.get_option("remote_addr")}',
|
||||
host=self.get_option('remote_addr'))
|
||||
|
||||
ssh = paramiko.SSHClient()
|
||||
|
||||
# Set pubkey and hostkey algorithms to disable, the only manipulation allowed currently
|
||||
# is keeping or omitting rsa-sha2 algorithms
|
||||
# default_keys: t.Tuple[str] = ()
|
||||
paramiko_preferred_pubkeys = getattr(paramiko.Transport, '_preferred_pubkeys', ())
|
||||
paramiko_preferred_hostkeys = getattr(paramiko.Transport, '_preferred_keys', ())
|
||||
use_rsa_sha2_algorithms = self.get_option('use_rsa_sha2_algorithms')
|
||||
disabled_algorithms: t.Dict[str, t.Iterable[str]] = {}
|
||||
if not use_rsa_sha2_algorithms:
|
||||
if paramiko_preferred_pubkeys:
|
||||
disabled_algorithms['pubkeys'] = tuple(a for a in paramiko_preferred_pubkeys if 'rsa-sha2' in a)
|
||||
if paramiko_preferred_hostkeys:
|
||||
disabled_algorithms['keys'] = tuple(a for a in paramiko_preferred_hostkeys if 'rsa-sha2' in a)
|
||||
|
||||
# override paramiko's default logger name
|
||||
if self._log_channel is not None:
|
||||
ssh.set_log_channel(self._log_channel)
|
||||
|
||||
self.keyfile = os.path.expanduser('~/.ssh/known_hosts')
|
||||
|
||||
if self.get_option('host_key_checking'):
|
||||
for ssh_known_hosts in ('/etc/ssh/ssh_known_hosts', '/etc/openssh/ssh_known_hosts'):
|
||||
try:
|
||||
ssh.load_system_host_keys(ssh_known_hosts)
|
||||
break
|
||||
except IOError:
|
||||
pass # file was not found, but not required to function
|
||||
except paramiko.hostkeys.InvalidHostKey as e:
|
||||
raise AnsibleConnectionFailure(f'Invalid host key: {to_text(e.line)}')
|
||||
try:
|
||||
ssh.load_system_host_keys()
|
||||
except paramiko.hostkeys.InvalidHostKey as e:
|
||||
raise AnsibleConnectionFailure(f'Invalid host key: {to_text(e.line)}')
|
||||
|
||||
ssh_connect_kwargs = self._parse_proxy_command(port)
|
||||
ssh.set_missing_host_key_policy(MyAddPolicy(self))
|
||||
conn_password = self.get_option('password')
|
||||
allow_agent = True
|
||||
|
||||
if conn_password is not None:
|
||||
allow_agent = False
|
||||
|
||||
try:
|
||||
key_filename = None
|
||||
if self.get_option('private_key_file'):
|
||||
key_filename = os.path.expanduser(self.get_option('private_key_file'))
|
||||
|
||||
# paramiko 2.2 introduced auth_timeout parameter
|
||||
if LooseVersion(paramiko.__version__) >= LooseVersion('2.2.0'):
|
||||
ssh_connect_kwargs['auth_timeout'] = self.get_option('timeout')
|
||||
|
||||
# paramiko 1.15 introduced banner timeout parameter
|
||||
if LooseVersion(paramiko.__version__) >= LooseVersion('1.15.0'):
|
||||
ssh_connect_kwargs['banner_timeout'] = self.get_option('banner_timeout')
|
||||
|
||||
ssh.connect(
|
||||
self.get_option('remote_addr').lower(),
|
||||
username=self.get_option('remote_user'),
|
||||
allow_agent=allow_agent,
|
||||
look_for_keys=self.get_option('look_for_keys'),
|
||||
key_filename=key_filename,
|
||||
password=conn_password,
|
||||
timeout=self.get_option('timeout'),
|
||||
port=port,
|
||||
disabled_algorithms=disabled_algorithms,
|
||||
**ssh_connect_kwargs,
|
||||
)
|
||||
except paramiko.ssh_exception.BadHostKeyException as e:
|
||||
raise AnsibleConnectionFailure(f'host key mismatch for {to_text(e.hostname)}')
|
||||
except paramiko.ssh_exception.AuthenticationException as e:
|
||||
msg = f'Failed to authenticate: {e}'
|
||||
raise AnsibleAuthenticationFailure(msg)
|
||||
except Exception as e:
|
||||
msg = to_text(e)
|
||||
if u'PID check failed' in msg:
|
||||
raise AnsibleError('paramiko version issue, please upgrade paramiko on the machine running ansible')
|
||||
elif u'Private key file is encrypted' in msg:
|
||||
msg = f'ssh {self.get_option("remote_user")}@{self.get_options("remote_addr")}:{port} : ' + \
|
||||
f'{msg}\nTo connect as a different user, use -u <username>.'
|
||||
raise AnsibleConnectionFailure(msg)
|
||||
else:
|
||||
raise AnsibleConnectionFailure(msg)
|
||||
self.ssh = ssh
|
||||
self._connected = True
|
||||
return self
|
||||
|
||||
def _any_keys_added(self) -> bool:
|
||||
for hostname, keys in self.ssh._host_keys.items():
|
||||
for keytype, key in keys.items():
|
||||
added_this_time = getattr(key, '_added_by_ansible_this_time', False)
|
||||
if added_this_time:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _save_ssh_host_keys(self, filename: str) -> None:
|
||||
"""
|
||||
not using the paramiko save_ssh_host_keys function as we want to add new SSH keys at the bottom so folks
|
||||
don't complain about it :)
|
||||
"""
|
||||
|
||||
if not self._any_keys_added():
|
||||
return
|
||||
|
||||
path = os.path.expanduser('~/.ssh')
|
||||
makedirs_safe(path)
|
||||
|
||||
with open(filename, 'w') as f:
|
||||
for hostname, keys in self.ssh._host_keys.items():
|
||||
for keytype, key in keys.items():
|
||||
# was f.write
|
||||
added_this_time = getattr(key, '_added_by_ansible_this_time', False)
|
||||
if not added_this_time:
|
||||
f.write(f'{hostname} {keytype} {key.get_base64()}\n')
|
||||
|
||||
for hostname, keys in self.ssh._host_keys.items():
|
||||
for keytype, key in keys.items():
|
||||
added_this_time = getattr(key, '_added_by_ansible_this_time', False)
|
||||
if added_this_time:
|
||||
f.write(f'{hostname} {keytype} {key.get_base64()}\n')
|
||||
|
||||
def _build_pct_command(self, cmd: str) -> str:
|
||||
cmd = ['/usr/sbin/pct', 'exec', str(self.get_option('vmid')), '--', cmd]
|
||||
if self.get_option('remote_user') != 'root':
|
||||
cmd = [self.get_option('proxmox_become_method')] + cmd
|
||||
display.vvv(f'INFO Running as non root user: {self.get_option("remote_user")}, trying to run pct with become method: ' +
|
||||
f'{self.get_option("proxmox_become_method")}',
|
||||
host=self.get_option('remote_addr'))
|
||||
return ' '.join(cmd)
|
||||
|
||||
def exec_command(self, cmd: str, in_data: bytes | None = None, sudoable: bool = True) -> tuple[int, bytes, bytes]:
|
||||
""" run a command on inside the LXC container """
|
||||
|
||||
cmd = self._build_pct_command(cmd)
|
||||
|
||||
super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
|
||||
|
||||
bufsize = 4096
|
||||
|
||||
try:
|
||||
self.ssh.get_transport().set_keepalive(5)
|
||||
chan = self.ssh.get_transport().open_session()
|
||||
except Exception as e:
|
||||
text_e = to_text(e)
|
||||
msg = 'Failed to open session'
|
||||
if text_e:
|
||||
msg += f': {text_e}'
|
||||
raise AnsibleConnectionFailure(to_native(msg))
|
||||
|
||||
# sudo usually requires a PTY (cf. requiretty option), therefore
|
||||
# we give it one by default (pty=True in ansible.cfg), and we try
|
||||
# to initialise from the calling environment when sudoable is enabled
|
||||
if self.get_option('pty') and sudoable:
|
||||
chan.get_pty(term=os.getenv('TERM', 'vt100'), width=int(os.getenv('COLUMNS', 0)), height=int(os.getenv('LINES', 0)))
|
||||
|
||||
display.vvv(f'EXEC {cmd}', host=self.get_option('remote_addr'))
|
||||
|
||||
cmd = to_bytes(cmd, errors='surrogate_or_strict')
|
||||
|
||||
no_prompt_out = b''
|
||||
no_prompt_err = b''
|
||||
become_output = b''
|
||||
|
||||
try:
|
||||
chan.exec_command(cmd)
|
||||
if self.become and self.become.expect_prompt():
|
||||
password_prompt = False
|
||||
become_success = False
|
||||
while not (become_success or password_prompt):
|
||||
display.debug('Waiting for Privilege Escalation input')
|
||||
|
||||
chunk = chan.recv(bufsize)
|
||||
display.debug(f'chunk is: {to_text(chunk)}')
|
||||
if not chunk:
|
||||
if b'unknown user' in become_output:
|
||||
n_become_user = to_native(self.become.get_option('become_user'))
|
||||
raise AnsibleError(f'user {n_become_user} does not exist')
|
||||
else:
|
||||
break
|
||||
# raise AnsibleError('ssh connection closed waiting for password prompt')
|
||||
become_output += chunk
|
||||
|
||||
# need to check every line because we might get lectured
|
||||
# and we might get the middle of a line in a chunk
|
||||
for line in become_output.splitlines(True):
|
||||
if self.become.check_success(line):
|
||||
become_success = True
|
||||
break
|
||||
elif self.become.check_password_prompt(line):
|
||||
password_prompt = True
|
||||
break
|
||||
|
||||
if password_prompt:
|
||||
if self.become:
|
||||
become_pass = self.become.get_option('become_pass')
|
||||
chan.sendall(to_bytes(become_pass, errors='surrogate_or_strict') + b'\n')
|
||||
else:
|
||||
raise AnsibleError('A password is required but none was supplied')
|
||||
else:
|
||||
no_prompt_out += become_output
|
||||
no_prompt_err += become_output
|
||||
|
||||
if in_data:
|
||||
for i in range(0, len(in_data), bufsize):
|
||||
chan.send(in_data[i:i + bufsize])
|
||||
chan.shutdown_write()
|
||||
elif in_data == b'':
|
||||
chan.shutdown_write()
|
||||
|
||||
except socket.timeout:
|
||||
raise AnsibleError('ssh timed out waiting for privilege escalation.\n' + to_text(become_output))
|
||||
|
||||
stdout = b''.join(chan.makefile('rb', bufsize))
|
||||
stderr = b''.join(chan.makefile_stderr('rb', bufsize))
|
||||
returncode = chan.recv_exit_status()
|
||||
|
||||
if 'pct: not found' in stderr.decode('utf-8'):
|
||||
raise AnsibleError(
|
||||
f'pct not found in path of host: {to_text(self.get_option("remote_addr"))}')
|
||||
|
||||
return (returncode, no_prompt_out + stdout, no_prompt_out + stderr)
|
||||
|
||||
def put_file(self, in_path: str, out_path: str) -> None:
|
||||
""" transfer a file from local to remote """
|
||||
|
||||
display.vvv(f'PUT {in_path} TO {out_path}', host=self.get_option('remote_addr'))
|
||||
try:
|
||||
with open(in_path, 'rb') as f:
|
||||
data = f.read()
|
||||
returncode, stdout, stderr = self.exec_command(
|
||||
' '.join([
|
||||
self._shell.executable, '-c',
|
||||
self._shell.quote(f'cat > {out_path}')]),
|
||||
in_data=data,
|
||||
sudoable=False)
|
||||
if returncode != 0:
|
||||
if 'cat: not found' in stderr.decode('utf-8'):
|
||||
raise AnsibleError(
|
||||
f'cat not found in path of container: {to_text(self.get_option("vmid"))}')
|
||||
raise AnsibleError(
|
||||
f'{to_text(stdout)}\n{to_text(stderr)}')
|
||||
except Exception as e:
|
||||
raise AnsibleError(
|
||||
f'error occurred while putting file from {in_path} to {out_path}!\n{to_text(e)}')
|
||||
|
||||
def fetch_file(self, in_path: str, out_path: str) -> None:
|
||||
""" save a remote file to the specified path """
|
||||
|
||||
display.vvv(f'FETCH {in_path} TO {out_path}', host=self.get_option('remote_addr'))
|
||||
try:
|
||||
returncode, stdout, stderr = self.exec_command(
|
||||
' '.join([
|
||||
self._shell.executable, '-c',
|
||||
self._shell.quote(f'cat {in_path}')]),
|
||||
sudoable=False)
|
||||
if returncode != 0:
|
||||
if 'cat: not found' in stderr.decode('utf-8'):
|
||||
raise AnsibleError(
|
||||
f'cat not found in path of container: {to_text(self.get_option("vmid"))}')
|
||||
raise AnsibleError(
|
||||
f'{to_text(stdout)}\n{to_text(stderr)}')
|
||||
with open(out_path, 'wb') as f:
|
||||
f.write(stdout)
|
||||
except Exception as e:
|
||||
raise AnsibleError(
|
||||
f'error occurred while fetching file from {in_path} to {out_path}!\n{to_text(e)}')
|
||||
|
||||
def reset(self) -> None:
|
||||
""" reset the connection """
|
||||
|
||||
if not self._connected:
|
||||
return
|
||||
self.close()
|
||||
self._connect()
|
||||
|
||||
def close(self) -> None:
|
||||
""" terminate the connection """
|
||||
|
||||
if self.get_option('host_key_checking') and self.get_option('record_host_keys') and self._any_keys_added():
|
||||
# add any new SSH host keys -- warning -- this could be slow
|
||||
# (This doesn't acquire the connection lock because it needs
|
||||
# to exclude only other known_hosts writers, not connections
|
||||
# that are starting up.)
|
||||
lockfile = os.path.basename(self.keyfile)
|
||||
dirname = os.path.dirname(self.keyfile)
|
||||
makedirs_safe(dirname)
|
||||
tmp_keyfile_name = None
|
||||
try:
|
||||
with FileLock().lock_file(lockfile, dirname, self.get_option('lock_file_timeout')):
|
||||
# just in case any were added recently
|
||||
|
||||
self.ssh.load_system_host_keys()
|
||||
self.ssh._host_keys.update(self.ssh._system_host_keys)
|
||||
|
||||
# gather information about the current key file, so
|
||||
# we can ensure the new file has the correct mode/owner
|
||||
|
||||
key_dir = os.path.dirname(self.keyfile)
|
||||
if os.path.exists(self.keyfile):
|
||||
key_stat = os.stat(self.keyfile)
|
||||
mode = key_stat.st_mode & 0o777
|
||||
uid = key_stat.st_uid
|
||||
gid = key_stat.st_gid
|
||||
else:
|
||||
mode = 0o644
|
||||
uid = os.getuid()
|
||||
gid = os.getgid()
|
||||
|
||||
# Save the new keys to a temporary file and move it into place
|
||||
# rather than rewriting the file. We set delete=False because
|
||||
# the file will be moved into place rather than cleaned up.
|
||||
|
||||
with tempfile.NamedTemporaryFile(dir=key_dir, delete=False) as tmp_keyfile:
|
||||
tmp_keyfile_name = tmp_keyfile.name
|
||||
os.chmod(tmp_keyfile_name, mode)
|
||||
os.chown(tmp_keyfile_name, uid, gid)
|
||||
self._save_ssh_host_keys(tmp_keyfile_name)
|
||||
|
||||
os.rename(tmp_keyfile_name, self.keyfile)
|
||||
except LockTimeout:
|
||||
raise AnsibleError(
|
||||
f'writing lock file for {self.keyfile} ran in to the timeout of {self.get_option("lock_file_timeout")}s')
|
||||
except paramiko.hostkeys.InvalidHostKey as e:
|
||||
raise AnsibleConnectionFailure(f'Invalid host key: {e.line}')
|
||||
except Exception as e:
|
||||
# unable to save keys, including scenario when key was invalid
|
||||
# and caught earlier
|
||||
raise AnsibleError(
|
||||
f'error occurred while writing SSH host keys!\n{to_text(e)}')
|
||||
finally:
|
||||
if tmp_keyfile_name is not None:
|
||||
pathlib.Path(tmp_keyfile_name).unlink(missing_ok=True)
|
||||
|
||||
self.ssh.close()
|
||||
self._connected = False
|
||||
28
plugins/doc_fragments/clc.py
Normal file
28
plugins/doc_fragments/clc.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2024, Alexei Znamensky <russoz@gmail.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class ModuleDocFragment(object):
|
||||
|
||||
# Standard documentation fragment
|
||||
DOCUMENTATION = r"""
|
||||
options: {}
|
||||
requirements:
|
||||
- requests >= 2.5.0
|
||||
- clc-sdk
|
||||
notes:
|
||||
- To use this module, it is required to set the below environment variables which enables access to the Centurylink Cloud.
|
||||
- E(CLC_V2_API_USERNAME), the account login ID for the Centurylink Cloud.
|
||||
- E(CLC_V2_API_PASSWORD), the account password for the Centurylink Cloud.
|
||||
- Alternatively, the module accepts the API token and account alias. The API token can be generated using the CLC account
|
||||
login and password using the HTTP API call @ U(https://api.ctl.io/v2/authentication/login).
|
||||
- E(CLC_V2_API_TOKEN), the API token generated from U(https://api.ctl.io/v2/authentication/login).
|
||||
- E(CLC_ACCT_ALIAS), the account alias associated with the Centurylink Cloud.
|
||||
- Users can set E(CLC_V2_API_URL) to specify an endpoint for pointing to a different CLC environment.
|
||||
"""
|
||||
@@ -14,6 +14,9 @@ options:
|
||||
global:
|
||||
description:
|
||||
- The module will pass the C(--global) argument to C(pipx), to execute actions in global scope.
|
||||
- The C(--global) is only available in C(pipx>=1.6.0), so make sure to have a compatible version when using this option.
|
||||
Moreover, a nasty bug with C(--global) was fixed in C(pipx==1.7.0), so it is strongly recommended you used that version
|
||||
or newer.
|
||||
type: bool
|
||||
default: false
|
||||
executable:
|
||||
@@ -22,9 +25,10 @@ options:
|
||||
- If not specified, the module will use C(python -m pipx) to run the tool, using the same Python interpreter as ansible
|
||||
itself.
|
||||
type: path
|
||||
requirements:
|
||||
- This module requires C(pipx) version 1.7.0 or above. Please note that C(pipx) 1.7.0 requires Python 3.8 or above.
|
||||
notes:
|
||||
- This module requires C(pipx) version 0.16.2.1 or above. From community.general 11.0.0 onwards, the module will require
|
||||
C(pipx>=1.7.0).
|
||||
- Please note that C(pipx) requires Python 3.6 or above.
|
||||
- This module does not install the C(pipx) python package, however that can be easily done with the module M(ansible.builtin.pip).
|
||||
- This module does not require C(pipx) to be in the shell C(PATH), but it must be loadable by Python as a module.
|
||||
- This module will honor C(pipx) environment variables such as but not limited to E(PIPX_HOME) and E(PIPX_BIN_DIR) passed
|
||||
|
||||
84
plugins/doc_fragments/proxmox.py
Normal file
84
plugins/doc_fragments/proxmox.py
Normal file
@@ -0,0 +1,84 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) Ansible project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class ModuleDocFragment(object):
|
||||
# Common parameters for Proxmox VE modules
|
||||
DOCUMENTATION = r"""
|
||||
options:
|
||||
api_host:
|
||||
description:
|
||||
- Specify the target host of the Proxmox VE cluster.
|
||||
type: str
|
||||
required: true
|
||||
api_port:
|
||||
description:
|
||||
- Specify the target port of the Proxmox VE cluster.
|
||||
- Uses the E(PROXMOX_PORT) environment variable if not specified.
|
||||
type: int
|
||||
required: false
|
||||
version_added: 9.1.0
|
||||
api_user:
|
||||
description:
|
||||
- Specify the user to authenticate with.
|
||||
type: str
|
||||
required: true
|
||||
api_password:
|
||||
description:
|
||||
- Specify the password to authenticate with.
|
||||
- You can use E(PROXMOX_PASSWORD) environment variable.
|
||||
type: str
|
||||
api_token_id:
|
||||
description:
|
||||
- Specify the token ID.
|
||||
- Requires C(proxmoxer>=1.1.0) to work.
|
||||
type: str
|
||||
version_added: 1.3.0
|
||||
api_token_secret:
|
||||
description:
|
||||
- Specify the token secret.
|
||||
- Requires C(proxmoxer>=1.1.0) to work.
|
||||
type: str
|
||||
version_added: 1.3.0
|
||||
validate_certs:
|
||||
description:
|
||||
- If V(false), SSL certificates will not be validated.
|
||||
- This should only be used on personally controlled sites using self-signed certificates.
|
||||
type: bool
|
||||
default: false
|
||||
requirements: ["proxmoxer", "requests"]
|
||||
"""
|
||||
|
||||
SELECTION = r"""
|
||||
options:
|
||||
vmid:
|
||||
description:
|
||||
- Specifies the instance ID.
|
||||
- If not set the next available ID will be fetched from ProxmoxAPI.
|
||||
type: int
|
||||
node:
|
||||
description:
|
||||
- Proxmox VE node on which to operate.
|
||||
- Only required for O(state=present).
|
||||
- For every other states it will be autodiscovered.
|
||||
type: str
|
||||
pool:
|
||||
description:
|
||||
- Add the new VM to the specified pool.
|
||||
type: str
|
||||
"""
|
||||
|
||||
ACTIONGROUP_PROXMOX = r"""
|
||||
options: {}
|
||||
attributes:
|
||||
action_group:
|
||||
description: Use C(group/community.general.proxmox) in C(module_defaults) to set defaults for this module.
|
||||
support: full
|
||||
membership:
|
||||
- community.general.proxmox
|
||||
"""
|
||||
@@ -291,11 +291,11 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||
self.group_by_hostgroups = self.get_option('group_by_hostgroups')
|
||||
|
||||
if self.templar.is_template(self.icinga2_url):
|
||||
self.icinga2_url = self.templar.template(variable=self.icinga2_url, disable_lookups=False)
|
||||
self.icinga2_url = self.templar.template(variable=self.icinga2_url)
|
||||
if self.templar.is_template(self.icinga2_user):
|
||||
self.icinga2_user = self.templar.template(variable=self.icinga2_user, disable_lookups=False)
|
||||
self.icinga2_user = self.templar.template(variable=self.icinga2_user)
|
||||
if self.templar.is_template(self.icinga2_password):
|
||||
self.icinga2_password = self.templar.template(variable=self.icinga2_password, disable_lookups=False)
|
||||
self.icinga2_password = self.templar.template(variable=self.icinga2_password)
|
||||
|
||||
self.icinga2_url = f"{self.icinga2_url.rstrip('/')}/v1"
|
||||
|
||||
|
||||
@@ -80,20 +80,6 @@ options:
|
||||
type: list
|
||||
elements: path
|
||||
version_added: 10.4.0
|
||||
inventory_hostname_tag:
|
||||
description:
|
||||
- The name of the tag in the C(iocage properties notes) that contains the jails alias.
|
||||
- By default, the C(iocage list -l) column C(NAME) is used to name the jail.
|
||||
- This option requires the notes format C("t1=v1 t2=v2 ...")
|
||||
- The option O(get_properties) must be enabled.
|
||||
type: str
|
||||
version_added: 11.0.0
|
||||
inventory_hostname_required:
|
||||
description:
|
||||
- If enabled, the tag declared in O(inventory_hostname_tag) is required.
|
||||
type: bool
|
||||
default: false
|
||||
version_added: 11.0.0
|
||||
notes:
|
||||
- You might want to test the command C(ssh user@host iocage list -l) on
|
||||
the controller before using this inventory plugin with O(user) specified
|
||||
@@ -267,8 +253,6 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
env = self.get_option('env')
|
||||
get_properties = self.get_option('get_properties')
|
||||
hooks_results = self.get_option('hooks_results')
|
||||
inventory_hostname_tag = self.get_option('inventory_hostname_tag')
|
||||
inventory_hostname_required = self.get_option('inventory_hostname_required')
|
||||
|
||||
cmd = []
|
||||
my_env = os.environ.copy()
|
||||
@@ -373,21 +357,6 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
|
||||
results['_meta']['hostvars'][hostname]['iocage_hooks'] = iocage_hooks
|
||||
|
||||
# Optionally, get the jails names from the properties notes.
|
||||
# Requires the notes format "t1=v1 t2=v2 ..."
|
||||
if inventory_hostname_tag:
|
||||
if not get_properties:
|
||||
raise AnsibleError('Jail properties are needed to use inventory_hostname_tag. Enable get_properties')
|
||||
update = {}
|
||||
for hostname, host_vars in results['_meta']['hostvars'].items():
|
||||
tags = dict(tag.split('=', 1) for tag in host_vars['iocage_properties']['notes'].split() if '=' in tag)
|
||||
if inventory_hostname_tag in tags:
|
||||
update[hostname] = tags[inventory_hostname_tag]
|
||||
elif inventory_hostname_required:
|
||||
raise AnsibleError(f'Mandatory tag {inventory_hostname_tag!r} is missing in the properties notes.')
|
||||
for hostname, alias in update.items():
|
||||
results['_meta']['hostvars'][alias] = results['_meta']['hostvars'].pop(hostname)
|
||||
|
||||
return results
|
||||
|
||||
def get_jails(self, t_stdout, results):
|
||||
|
||||
@@ -150,7 +150,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
|
||||
access_token = self.get_option('access_token')
|
||||
if self.templar.is_template(access_token):
|
||||
access_token = self.templar.template(variable=access_token, disable_lookups=False)
|
||||
access_token = self.templar.template(variable=access_token)
|
||||
|
||||
if access_token is None:
|
||||
raise AnsibleError((
|
||||
|
||||
715
plugins/inventory/proxmox.py
Normal file
715
plugins/inventory/proxmox.py
Normal file
@@ -0,0 +1,715 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2016 Guido Günther <agx@sigxcpu.org>, Daniel Lobato Garcia <dlobatog@redhat.com>
|
||||
# Copyright (c) 2018 Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
name: proxmox
|
||||
short_description: Proxmox inventory source
|
||||
version_added: "1.2.0"
|
||||
author:
|
||||
- Jeffrey van Pelt (@Thulium-Drake) <jeff@vanpelt.one>
|
||||
requirements:
|
||||
- requests >= 1.1
|
||||
description:
|
||||
- Get inventory hosts from a Proxmox PVE cluster.
|
||||
- "Uses a configuration file as an inventory source, it must end in C(.proxmox.yml) or C(.proxmox.yaml)"
|
||||
- Will retrieve the first network interface with an IP for Proxmox nodes.
|
||||
- Can retrieve LXC/QEMU configuration as facts.
|
||||
extends_documentation_fragment:
|
||||
- constructed
|
||||
- inventory_cache
|
||||
options:
|
||||
plugin:
|
||||
description: The name of this plugin, it should always be set to V(community.general.proxmox) for this plugin to recognize it as its own.
|
||||
required: true
|
||||
choices: ['community.general.proxmox']
|
||||
type: str
|
||||
url:
|
||||
description:
|
||||
- URL to Proxmox cluster.
|
||||
- If the value is not specified in the inventory configuration, the value of environment variable E(PROXMOX_URL) will be used instead.
|
||||
- Since community.general 4.7.0 you can also use templating to specify the value of the O(url).
|
||||
default: 'http://localhost:8006'
|
||||
type: str
|
||||
env:
|
||||
- name: PROXMOX_URL
|
||||
version_added: 2.0.0
|
||||
user:
|
||||
description:
|
||||
- Proxmox authentication user.
|
||||
- If the value is not specified in the inventory configuration, the value of environment variable E(PROXMOX_USER) will be used instead.
|
||||
- Since community.general 4.7.0 you can also use templating to specify the value of the O(user).
|
||||
required: true
|
||||
type: str
|
||||
env:
|
||||
- name: PROXMOX_USER
|
||||
version_added: 2.0.0
|
||||
password:
|
||||
description:
|
||||
- Proxmox authentication password.
|
||||
- If the value is not specified in the inventory configuration, the value of environment variable E(PROXMOX_PASSWORD) will be used instead.
|
||||
- Since community.general 4.7.0 you can also use templating to specify the value of the O(password).
|
||||
- If you do not specify a password, you must set O(token_id) and O(token_secret) instead.
|
||||
type: str
|
||||
env:
|
||||
- name: PROXMOX_PASSWORD
|
||||
version_added: 2.0.0
|
||||
token_id:
|
||||
description:
|
||||
- Proxmox authentication token ID.
|
||||
- If the value is not specified in the inventory configuration, the value of environment variable E(PROXMOX_TOKEN_ID) will be used instead.
|
||||
- To use token authentication, you must also specify O(token_secret). If you do not specify O(token_id) and O(token_secret),
|
||||
you must set a password instead.
|
||||
- Make sure to grant explicit pve permissions to the token or disable 'privilege separation' to use the users' privileges instead.
|
||||
version_added: 4.8.0
|
||||
type: str
|
||||
env:
|
||||
- name: PROXMOX_TOKEN_ID
|
||||
token_secret:
|
||||
description:
|
||||
- Proxmox authentication token secret.
|
||||
- If the value is not specified in the inventory configuration, the value of environment variable E(PROXMOX_TOKEN_SECRET) will be used instead.
|
||||
- To use token authentication, you must also specify O(token_id). If you do not specify O(token_id) and O(token_secret),
|
||||
you must set a password instead.
|
||||
version_added: 4.8.0
|
||||
type: str
|
||||
env:
|
||||
- name: PROXMOX_TOKEN_SECRET
|
||||
validate_certs:
|
||||
description: Verify SSL certificate if using HTTPS.
|
||||
type: boolean
|
||||
default: true
|
||||
group_prefix:
|
||||
description: Prefix to apply to Proxmox groups.
|
||||
default: proxmox_
|
||||
type: str
|
||||
facts_prefix:
|
||||
description: Prefix to apply to LXC/QEMU config facts.
|
||||
default: proxmox_
|
||||
type: str
|
||||
want_facts:
|
||||
description:
|
||||
- Gather LXC/QEMU configuration facts.
|
||||
- When O(want_facts) is set to V(true) more details about QEMU VM status are possible, besides the running and stopped states.
|
||||
Currently if the VM is running and it is suspended, the status will be running and the machine will be in C(running) group,
|
||||
but its actual state will be paused. See O(qemu_extended_statuses) for how to retrieve the real status.
|
||||
default: false
|
||||
type: bool
|
||||
qemu_extended_statuses:
|
||||
description:
|
||||
- Requires O(want_facts) to be set to V(true) to function. This will allow you to differentiate between C(paused) and C(prelaunch)
|
||||
statuses of the QEMU VMs.
|
||||
- This introduces multiple groups [prefixed with O(group_prefix)] C(prelaunch) and C(paused).
|
||||
default: false
|
||||
type: bool
|
||||
version_added: 5.1.0
|
||||
want_proxmox_nodes_ansible_host:
|
||||
version_added: 3.0.0
|
||||
description:
|
||||
- Whether to set C(ansible_host) for proxmox nodes.
|
||||
- When set to V(true) (default), will use the first available interface. This can be different from what you expect.
|
||||
- The default of this option changed from V(true) to V(false) in community.general 6.0.0.
|
||||
type: bool
|
||||
default: false
|
||||
exclude_nodes:
|
||||
description: Exclude proxmox nodes and the nodes-group from the inventory output.
|
||||
type: bool
|
||||
default: false
|
||||
version_added: 8.1.0
|
||||
filters:
|
||||
version_added: 4.6.0
|
||||
description: A list of Jinja templates that allow filtering hosts.
|
||||
type: list
|
||||
elements: str
|
||||
default: []
|
||||
strict:
|
||||
version_added: 2.5.0
|
||||
compose:
|
||||
version_added: 2.5.0
|
||||
groups:
|
||||
version_added: 2.5.0
|
||||
keyed_groups:
|
||||
version_added: 2.5.0
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
---
|
||||
# Minimal example which will not gather additional facts for QEMU/LXC guests
|
||||
# By not specifying a URL the plugin will attempt to connect to the controller host on port 8006
|
||||
# my.proxmox.yml
|
||||
plugin: community.general.proxmox
|
||||
user: ansible@pve
|
||||
password: secure
|
||||
# Note that this can easily give you wrong values as ansible_host. See further below for
|
||||
# an example where this is set to `false` and where ansible_host is set with `compose`.
|
||||
want_proxmox_nodes_ansible_host: true
|
||||
|
||||
---
|
||||
# Instead of login with password, proxmox supports api token authentication since release 6.2.
|
||||
plugin: community.general.proxmox
|
||||
user: ci@pve
|
||||
token_id: gitlab-1
|
||||
token_secret: fa256e9c-26ab-41ec-82da-707a2c079829
|
||||
|
||||
---
|
||||
# The secret can also be a vault string or passed via the environment variable TOKEN_SECRET.
|
||||
plugin: community.general.proxmox
|
||||
user: ci@pve
|
||||
token_id: gitlab-1
|
||||
token_secret: !vault |
|
||||
$ANSIBLE_VAULT;1.1;AES256
|
||||
62353634333163633336343265623632626339313032653563653165313262343931643431656138
|
||||
6134333736323265656466646539663134306166666237630a653363623262636663333762316136
|
||||
34616361326263383766366663393837626437316462313332663736623066656237386531663731
|
||||
3037646432383064630a663165303564623338666131353366373630656661333437393937343331
|
||||
32643131386134396336623736393634373936356332623632306561356361323737313663633633
|
||||
6231313333666361656537343562333337323030623732323833
|
||||
|
||||
---
|
||||
# More complete example demonstrating the use of 'want_facts' and the constructed options
|
||||
# Note that using facts returned by 'want_facts' in constructed options requires 'want_facts=true'
|
||||
# my.proxmox.yml
|
||||
plugin: community.general.proxmox
|
||||
url: http://pve.domain.com:8006
|
||||
user: ansible@pve
|
||||
password: secure
|
||||
want_facts: true
|
||||
keyed_groups:
|
||||
# proxmox_tags_parsed is an example of a fact only returned when 'want_facts=true'
|
||||
- key: proxmox_tags_parsed
|
||||
separator: ""
|
||||
prefix: group
|
||||
groups:
|
||||
webservers: "'web' in (proxmox_tags_parsed|list)"
|
||||
mailservers: "'mail' in (proxmox_tags_parsed|list)"
|
||||
compose:
|
||||
ansible_port: 2222
|
||||
# Note that this can easily give you wrong values as ansible_host. See further below for
|
||||
# an example where this is set to `false` and where ansible_host is set with `compose`.
|
||||
want_proxmox_nodes_ansible_host: true
|
||||
|
||||
---
|
||||
# Using the inventory to allow ansible to connect via the first IP address of the VM / Container
|
||||
# (Default is connection by name of QEMU/LXC guests)
|
||||
# Note: my_inv_var demonstrates how to add a string variable to every host used by the inventory.
|
||||
# my.proxmox.yml
|
||||
plugin: community.general.proxmox
|
||||
url: http://192.168.1.2:8006
|
||||
user: ansible@pve
|
||||
password: secure
|
||||
validate_certs: false # only do this when you trust the network!
|
||||
want_facts: true
|
||||
want_proxmox_nodes_ansible_host: false
|
||||
compose:
|
||||
ansible_host: proxmox_ipconfig0.ip | default(proxmox_net0.ip) | ipaddr('address')
|
||||
my_inv_var_1: "'my_var1_value'"
|
||||
my_inv_var_2: >
|
||||
"my_var_2_value"
|
||||
|
||||
---
|
||||
# Specify the url, user and password using templating
|
||||
# my.proxmox.yml
|
||||
plugin: community.general.proxmox
|
||||
url: "{{ lookup('ansible.builtin.ini', 'url', section='proxmox', file='file.ini') }}"
|
||||
user: "{{ lookup('ansible.builtin.env','PM_USER') | default('ansible@pve') }}"
|
||||
password: "{{ lookup('community.general.random_string', base64=True) }}"
|
||||
# Note that this can easily give you wrong values as ansible_host. See further up for
|
||||
# an example where this is set to `false` and where ansible_host is set with `compose`.
|
||||
want_proxmox_nodes_ansible_host: true
|
||||
'''
|
||||
|
||||
import itertools
|
||||
import re
|
||||
|
||||
from ansible.module_utils.common._collections_compat import MutableMapping
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
from ansible.utils.display import Display
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
||||
|
||||
# 3rd party imports
|
||||
try:
|
||||
import requests
|
||||
if LooseVersion(requests.__version__) < LooseVersion('1.1.0'):
|
||||
raise ImportError
|
||||
HAS_REQUESTS = True
|
||||
except ImportError:
|
||||
HAS_REQUESTS = False
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
''' Host inventory parser for ansible using Proxmox as source. '''
|
||||
|
||||
NAME = 'community.general.proxmox'
|
||||
|
||||
def __init__(self):
|
||||
|
||||
super(InventoryModule, self).__init__()
|
||||
|
||||
# from config
|
||||
self.proxmox_url = None
|
||||
|
||||
self.session = None
|
||||
self.cache_key = None
|
||||
self.use_cache = None
|
||||
|
||||
def verify_file(self, path):
|
||||
|
||||
valid = False
|
||||
if super(InventoryModule, self).verify_file(path):
|
||||
if path.endswith(('proxmox.yaml', 'proxmox.yml')):
|
||||
valid = True
|
||||
else:
|
||||
self.display.vvv('Skipping due to inventory source not ending in "proxmox.yaml" nor "proxmox.yml"')
|
||||
return valid
|
||||
|
||||
def _get_session(self):
|
||||
if not self.session:
|
||||
self.session = requests.session()
|
||||
self.session.verify = self.get_option('validate_certs')
|
||||
return self.session
|
||||
|
||||
def _get_auth(self):
|
||||
validate_certs = self.get_option('validate_certs')
|
||||
|
||||
if validate_certs is False:
|
||||
from requests.packages.urllib3 import disable_warnings
|
||||
disable_warnings()
|
||||
|
||||
if self.proxmox_password:
|
||||
credentials = urlencode({'username': self.proxmox_user, 'password': self.proxmox_password})
|
||||
a = self._get_session()
|
||||
ret = a.post(f'{self.proxmox_url}/api2/json/access/ticket', data=credentials)
|
||||
json = ret.json()
|
||||
self.headers = {
|
||||
# only required for POST/PUT/DELETE methods, which we are not using currently
|
||||
# 'CSRFPreventionToken': json['data']['CSRFPreventionToken'],
|
||||
'Cookie': f"PVEAuthCookie={json['data']['ticket']}"
|
||||
}
|
||||
else:
|
||||
# Clean and format token components
|
||||
user = self.proxmox_user.strip()
|
||||
token_id = self.proxmox_token_id.strip()
|
||||
token_secret = self.proxmox_token_secret.strip()
|
||||
|
||||
# Build token string without newlines
|
||||
token = f'{user}!{token_id}={token_secret}'
|
||||
|
||||
# Set headers with clean token
|
||||
self.headers = {'Authorization': f'PVEAPIToken={token}'}
|
||||
|
||||
def _get_json(self, url, ignore_errors=None):
|
||||
|
||||
data = []
|
||||
has_data = False
|
||||
|
||||
if self.use_cache:
|
||||
try:
|
||||
data = self._cache[self.cache_key][url]
|
||||
has_data = True
|
||||
except KeyError:
|
||||
self.update_cache = True
|
||||
|
||||
if not has_data:
|
||||
s = self._get_session()
|
||||
while True:
|
||||
ret = s.get(url, headers=self.headers)
|
||||
if ignore_errors and ret.status_code in ignore_errors:
|
||||
break
|
||||
ret.raise_for_status()
|
||||
json = ret.json()
|
||||
|
||||
# process results
|
||||
# FIXME: This assumes 'return type' matches a specific query,
|
||||
# it will break if we expand the queries and they dont have different types
|
||||
if 'data' not in json:
|
||||
# /hosts/:id does not have a 'data' key
|
||||
data = json
|
||||
break
|
||||
elif isinstance(json['data'], MutableMapping):
|
||||
# /facts are returned as dict in 'data'
|
||||
data = json['data']
|
||||
break
|
||||
else:
|
||||
if json['data']:
|
||||
# /hosts 's 'results' is a list of all hosts, returned is paginated
|
||||
data = data + json['data']
|
||||
break
|
||||
|
||||
self._results[url] = data
|
||||
return make_unsafe(data)
|
||||
|
||||
def _get_nodes(self):
|
||||
return self._get_json(f"{self.proxmox_url}/api2/json/nodes")
|
||||
|
||||
def _get_pools(self):
|
||||
return self._get_json(f"{self.proxmox_url}/api2/json/pools")
|
||||
|
||||
def _get_lxc_per_node(self, node):
|
||||
return self._get_json(f"{self.proxmox_url}/api2/json/nodes/{node}/lxc")
|
||||
|
||||
def _get_qemu_per_node(self, node):
|
||||
return self._get_json(f"{self.proxmox_url}/api2/json/nodes/{node}/qemu")
|
||||
|
||||
def _get_members_per_pool(self, pool):
|
||||
ret = self._get_json(f"{self.proxmox_url}/api2/json/pools/{pool}")
|
||||
return ret['members']
|
||||
|
||||
def _get_node_ip(self, node):
|
||||
ret = self._get_json(f"{self.proxmox_url}/api2/json/nodes/{node}/network")
|
||||
|
||||
# sort interface by iface name to make selection as stable as possible
|
||||
ret.sort(key=lambda x: x['iface'])
|
||||
|
||||
for iface in ret:
|
||||
try:
|
||||
# only process interfaces adhering to these rules
|
||||
if 'active' not in iface:
|
||||
self.display.vvv(f"Interface {iface['iface']} on node {node} does not have an active state")
|
||||
continue
|
||||
if 'address' not in iface:
|
||||
self.display.vvv(f"Interface {iface['iface']} on node {node} does not have an address")
|
||||
continue
|
||||
if 'gateway' not in iface:
|
||||
self.display.vvv(f"Interface {iface['iface']} on node {node} does not have a gateway")
|
||||
continue
|
||||
self.display.vv(f"Using interface {iface['iface']} on node {node} with address {iface['address']} as node ip for ansible_host")
|
||||
return iface['address']
|
||||
except Exception:
|
||||
continue
|
||||
return None
|
||||
|
||||
def _get_lxc_interfaces(self, properties, node, vmid):
|
||||
status_key = self._fact('status')
|
||||
|
||||
if status_key not in properties or not properties[status_key] == 'running':
|
||||
return
|
||||
|
||||
ret = self._get_json(f"{self.proxmox_url}/api2/json/nodes/{node}/lxc/{vmid}/interfaces", ignore_errors=[501])
|
||||
if not ret:
|
||||
return
|
||||
|
||||
result = []
|
||||
|
||||
for iface in ret:
|
||||
result_iface = {
|
||||
'name': iface['name'],
|
||||
'hwaddr': iface['hwaddr']
|
||||
}
|
||||
|
||||
if 'inet' in iface:
|
||||
result_iface['inet'] = iface['inet']
|
||||
|
||||
if 'inet6' in iface:
|
||||
result_iface['inet6'] = iface['inet6']
|
||||
|
||||
result.append(result_iface)
|
||||
|
||||
properties[self._fact('lxc_interfaces')] = result
|
||||
|
||||
def _get_agent_network_interfaces(self, node, vmid, vmtype):
|
||||
result = []
|
||||
|
||||
try:
|
||||
ifaces = self._get_json(
|
||||
f"{self.proxmox_url}/api2/json/nodes/{node}/{vmtype}/{vmid}/agent/network-get-interfaces"
|
||||
)['result']
|
||||
|
||||
if "error" in ifaces:
|
||||
if "class" in ifaces["error"]:
|
||||
# This happens on Windows, even though qemu agent is running, the IP address
|
||||
# cannot be fetched, as it is unsupported, also a command disabled can happen.
|
||||
errorClass = ifaces["error"]["class"]
|
||||
if errorClass in ["Unsupported"]:
|
||||
self.display.v("Retrieving network interfaces from guest agents on windows with older qemu-guest-agents is not supported")
|
||||
elif errorClass in ["CommandDisabled"]:
|
||||
self.display.v("Retrieving network interfaces from guest agents has been disabled")
|
||||
return result
|
||||
|
||||
for iface in ifaces:
|
||||
result.append({
|
||||
'name': iface['name'],
|
||||
'mac-address': iface['hardware-address'] if 'hardware-address' in iface else '',
|
||||
'ip-addresses': [f"{ip['ip-address']}/{ip['prefix']}" for ip in iface['ip-addresses']] if 'ip-addresses' in iface else []
|
||||
})
|
||||
except requests.HTTPError:
|
||||
pass
|
||||
|
||||
return result
|
||||
|
||||
def _get_vm_config(self, properties, node, vmid, vmtype, name):
|
||||
ret = self._get_json(f"{self.proxmox_url}/api2/json/nodes/{node}/{vmtype}/{vmid}/config")
|
||||
|
||||
properties[self._fact('node')] = node
|
||||
properties[self._fact('vmid')] = vmid
|
||||
properties[self._fact('vmtype')] = vmtype
|
||||
|
||||
plaintext_configs = [
|
||||
'description',
|
||||
]
|
||||
|
||||
for config in ret:
|
||||
key = self._fact(config)
|
||||
value = ret[config]
|
||||
try:
|
||||
# fixup disk images as they have no key
|
||||
if config == 'rootfs' or config.startswith(('virtio', 'sata', 'ide', 'scsi')):
|
||||
value = f"disk_image={value}"
|
||||
|
||||
# Additional field containing parsed tags as list
|
||||
if config == 'tags':
|
||||
stripped_value = value.strip()
|
||||
if stripped_value:
|
||||
parsed_key = f"{key}_parsed"
|
||||
properties[parsed_key] = [tag.strip() for tag in stripped_value.replace(',', ';').split(";")]
|
||||
|
||||
# The first field in the agent string tells you whether the agent is enabled
|
||||
# the rest of the comma separated string is extra config for the agent.
|
||||
# In some (newer versions of proxmox) instances it can be 'enabled=1'.
|
||||
if config == 'agent':
|
||||
agent_enabled = 0
|
||||
try:
|
||||
agent_enabled = int(value.split(',')[0])
|
||||
except ValueError:
|
||||
if value.split(',')[0] == "enabled=1":
|
||||
agent_enabled = 1
|
||||
if agent_enabled:
|
||||
agent_iface_value = self._get_agent_network_interfaces(node, vmid, vmtype)
|
||||
if agent_iface_value:
|
||||
agent_iface_key = self.to_safe(f'{key}_interfaces')
|
||||
properties[agent_iface_key] = agent_iface_value
|
||||
|
||||
if config == 'lxc':
|
||||
out_val = {}
|
||||
for k, v in value:
|
||||
if k.startswith('lxc.'):
|
||||
k = k[len('lxc.'):]
|
||||
out_val[k] = v
|
||||
value = out_val
|
||||
|
||||
if config not in plaintext_configs and isinstance(value, string_types) \
|
||||
and all("=" in v for v in value.split(",")):
|
||||
# split off strings with commas to a dict
|
||||
# skip over any keys that cannot be processed
|
||||
try:
|
||||
value = dict(key.split("=", 1) for key in value.split(","))
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
properties[key] = value
|
||||
except NameError:
|
||||
return None
|
||||
|
||||
def _get_vm_status(self, properties, node, vmid, vmtype, name):
|
||||
ret = self._get_json(f"{self.proxmox_url}/api2/json/nodes/{node}/{vmtype}/{vmid}/status/current")
|
||||
properties[self._fact('status')] = ret['status']
|
||||
if vmtype == 'qemu':
|
||||
properties[self._fact('qmpstatus')] = ret['qmpstatus']
|
||||
|
||||
def _get_vm_snapshots(self, properties, node, vmid, vmtype, name):
|
||||
ret = self._get_json(f"{self.proxmox_url}/api2/json/nodes/{node}/{vmtype}/{vmid}/snapshot")
|
||||
snapshots = [snapshot['name'] for snapshot in ret if snapshot['name'] != 'current']
|
||||
properties[self._fact('snapshots')] = snapshots
|
||||
|
||||
def to_safe(self, word):
|
||||
'''Converts 'bad' characters in a string to underscores so they can be used as Ansible groups
|
||||
#> ProxmoxInventory.to_safe("foo-bar baz")
|
||||
'foo_barbaz'
|
||||
'''
|
||||
regex = r"[^A-Za-z0-9\_]"
|
||||
return re.sub(regex, "_", word.replace(" ", ""))
|
||||
|
||||
def _fact(self, name):
|
||||
'''Generate a fact's full name from the common prefix and a name.'''
|
||||
return self.to_safe(f'{self.facts_prefix}{name.lower()}')
|
||||
|
||||
def _group(self, name):
|
||||
'''Generate a group's full name from the common prefix and a name.'''
|
||||
return self.to_safe(f'{self.group_prefix}{name.lower()}')
|
||||
|
||||
def _can_add_host(self, name, properties):
|
||||
'''Ensure that a host satisfies all defined hosts filters. If strict mode is
|
||||
enabled, any error during host filter compositing will lead to an AnsibleError
|
||||
being raised, otherwise the filter will be ignored.
|
||||
'''
|
||||
for host_filter in self.host_filters:
|
||||
try:
|
||||
if not self._compose(host_filter, properties):
|
||||
return False
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
message = f"Could not evaluate host filter {host_filter} for host {name} - {e}"
|
||||
if self.strict:
|
||||
raise AnsibleError(message)
|
||||
display.warning(message)
|
||||
return True
|
||||
|
||||
def _add_host(self, name, variables):
|
||||
self.inventory.add_host(name)
|
||||
for k, v in variables.items():
|
||||
self.inventory.set_variable(name, k, v)
|
||||
variables = self.inventory.get_host(name).get_vars()
|
||||
self._set_composite_vars(self.get_option('compose'), variables, name, strict=self.strict)
|
||||
self._add_host_to_composed_groups(self.get_option('groups'), variables, name, strict=self.strict)
|
||||
self._add_host_to_keyed_groups(self.get_option('keyed_groups'), variables, name, strict=self.strict)
|
||||
|
||||
def _handle_item(self, node, ittype, item):
|
||||
'''Handle an item from the list of LXC containers and Qemu VM. The
|
||||
return value will be either None if the item was skipped or the name of
|
||||
the item if it was added to the inventory.'''
|
||||
if item.get('template'):
|
||||
return None
|
||||
|
||||
properties = dict()
|
||||
name, vmid = item['name'], item['vmid']
|
||||
|
||||
# get status, config and snapshots if want_facts == True
|
||||
want_facts = self.get_option('want_facts')
|
||||
if want_facts:
|
||||
self._get_vm_status(properties, node, vmid, ittype, name)
|
||||
self._get_vm_config(properties, node, vmid, ittype, name)
|
||||
self._get_vm_snapshots(properties, node, vmid, ittype, name)
|
||||
|
||||
if ittype == 'lxc':
|
||||
self._get_lxc_interfaces(properties, node, vmid)
|
||||
|
||||
# ensure the host satisfies filters
|
||||
if not self._can_add_host(name, properties):
|
||||
return None
|
||||
|
||||
# add the host to the inventory
|
||||
self._add_host(name, properties)
|
||||
node_type_group = self._group(f'{node}_{ittype}')
|
||||
self.inventory.add_child(self._group(f"all_{ittype}"), name)
|
||||
self.inventory.add_child(node_type_group, name)
|
||||
|
||||
item_status = item['status']
|
||||
if item_status == 'running':
|
||||
if want_facts and ittype == 'qemu' and self.get_option('qemu_extended_statuses'):
|
||||
# get more details about the status of the qemu VM
|
||||
item_status = properties.get(self._fact('qmpstatus'), item_status)
|
||||
self.inventory.add_child(self._group(f'all_{item_status}'), name)
|
||||
|
||||
return name
|
||||
|
||||
def _populate_pool_groups(self, added_hosts):
|
||||
'''Generate groups from Proxmox resource pools, ignoring VMs and
|
||||
containers that were skipped.'''
|
||||
for pool in self._get_pools():
|
||||
poolid = pool.get('poolid')
|
||||
if not poolid:
|
||||
continue
|
||||
pool_group = self._group(f"pool_{poolid}")
|
||||
self.inventory.add_group(pool_group)
|
||||
|
||||
for member in self._get_members_per_pool(poolid):
|
||||
name = member.get('name')
|
||||
if name and name in added_hosts:
|
||||
self.inventory.add_child(pool_group, name)
|
||||
|
||||
def _populate(self):
|
||||
|
||||
# create common groups
|
||||
default_groups = ['lxc', 'qemu', 'running', 'stopped']
|
||||
|
||||
if self.get_option('qemu_extended_statuses'):
|
||||
default_groups.extend(['prelaunch', 'paused'])
|
||||
|
||||
for group in default_groups:
|
||||
self.inventory.add_group(self._group(f'all_{group}'))
|
||||
nodes_group = self._group('nodes')
|
||||
if not self.exclude_nodes:
|
||||
self.inventory.add_group(nodes_group)
|
||||
|
||||
want_proxmox_nodes_ansible_host = self.get_option("want_proxmox_nodes_ansible_host")
|
||||
|
||||
# gather vm's on nodes
|
||||
self._get_auth()
|
||||
hosts = []
|
||||
for node in self._get_nodes():
|
||||
if not node.get('node'):
|
||||
continue
|
||||
if not self.exclude_nodes:
|
||||
self.inventory.add_host(node['node'])
|
||||
if node['type'] == 'node' and not self.exclude_nodes:
|
||||
self.inventory.add_child(nodes_group, node['node'])
|
||||
|
||||
if node['status'] == 'offline':
|
||||
continue
|
||||
|
||||
# get node IP address
|
||||
if want_proxmox_nodes_ansible_host and not self.exclude_nodes:
|
||||
ip = self._get_node_ip(node['node'])
|
||||
self.inventory.set_variable(node['node'], 'ansible_host', ip)
|
||||
|
||||
# Setting composite variables
|
||||
if not self.exclude_nodes:
|
||||
variables = self.inventory.get_host(node['node']).get_vars()
|
||||
self._set_composite_vars(self.get_option('compose'), variables, node['node'], strict=self.strict)
|
||||
|
||||
# add LXC/Qemu groups for the node
|
||||
for ittype in ('lxc', 'qemu'):
|
||||
node_type_group = self._group(f"{node['node']}_{ittype}")
|
||||
self.inventory.add_group(node_type_group)
|
||||
|
||||
# get LXC containers and Qemu VMs for this node
|
||||
lxc_objects = zip(itertools.repeat('lxc'), self._get_lxc_per_node(node['node']))
|
||||
qemu_objects = zip(itertools.repeat('qemu'), self._get_qemu_per_node(node['node']))
|
||||
for ittype, item in itertools.chain(lxc_objects, qemu_objects):
|
||||
name = self._handle_item(node['node'], ittype, item)
|
||||
if name is not None:
|
||||
hosts.append(name)
|
||||
|
||||
# gather vm's in pools
|
||||
self._populate_pool_groups(hosts)
|
||||
|
||||
def parse(self, inventory, loader, path, cache=True):
|
||||
if not HAS_REQUESTS:
|
||||
raise AnsibleError('This module requires Python Requests 1.1.0 or higher: '
|
||||
'https://github.com/psf/requests.')
|
||||
|
||||
super(InventoryModule, self).parse(inventory, loader, path)
|
||||
|
||||
# read config from file, this sets 'options'
|
||||
self._read_config_data(path)
|
||||
|
||||
# read and template auth options
|
||||
for o in ('url', 'user', 'password', 'token_id', 'token_secret'):
|
||||
v = self.get_option(o)
|
||||
if self.templar.is_template(v):
|
||||
v = self.templar.template(v, disable_lookups=False)
|
||||
setattr(self, f'proxmox_{o}', v)
|
||||
|
||||
# some more cleanup and validation
|
||||
self.proxmox_url = self.proxmox_url.rstrip('/')
|
||||
|
||||
if self.proxmox_password is None and (self.proxmox_token_id is None or self.proxmox_token_secret is None):
|
||||
raise AnsibleError('You must specify either a password or both token_id and token_secret.')
|
||||
|
||||
if self.get_option('qemu_extended_statuses') and not self.get_option('want_facts'):
|
||||
raise AnsibleError('You must set want_facts to True if you want to use qemu_extended_statuses.')
|
||||
# read rest of options
|
||||
self.exclude_nodes = self.get_option('exclude_nodes')
|
||||
self.cache_key = self.get_cache_key(path)
|
||||
self.use_cache = cache and self.get_option('cache')
|
||||
self.update_cache = not cache and self.get_option('cache')
|
||||
self.host_filters = self.get_option('filters')
|
||||
self.group_prefix = self.get_option('group_prefix')
|
||||
self.facts_prefix = self.get_option('facts_prefix')
|
||||
self.strict = self.get_option('strict')
|
||||
|
||||
# actually populate inventory
|
||||
self._results = {}
|
||||
self._populate()
|
||||
if self.update_cache:
|
||||
self._cache[self.cache_key] = self._results
|
||||
285
plugins/inventory/stackpath_compute.py
Normal file
285
plugins/inventory/stackpath_compute.py
Normal file
@@ -0,0 +1,285 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2020 Shay Rybak <shay.rybak@stackpath.com>
|
||||
# Copyright (c) 2020 Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
name: stackpath_compute
|
||||
short_description: StackPath Edge Computing inventory source
|
||||
version_added: 1.2.0
|
||||
author:
|
||||
- UNKNOWN (@shayrybak)
|
||||
deprecated:
|
||||
removed_in: 11.0.0
|
||||
why: Stackpath (the company) ceased its operations in June 2024. The API URL this plugin relies on is not found in DNS.
|
||||
alternative: There is none.
|
||||
extends_documentation_fragment:
|
||||
- inventory_cache
|
||||
- constructed
|
||||
description:
|
||||
- Get inventory hosts from StackPath Edge Computing.
|
||||
- Uses a YAML configuration file that ends with stackpath_compute.(yml|yaml).
|
||||
options:
|
||||
plugin:
|
||||
description:
|
||||
- A token that ensures this is a source file for the plugin.
|
||||
required: true
|
||||
type: string
|
||||
choices: ['community.general.stackpath_compute']
|
||||
client_id:
|
||||
description:
|
||||
- An OAuth client ID generated from the API Management section of the StackPath customer portal U(https://control.stackpath.net/api-management).
|
||||
required: true
|
||||
type: str
|
||||
client_secret:
|
||||
description:
|
||||
- An OAuth client secret generated from the API Management section of the StackPath customer portal U(https://control.stackpath.net/api-management).
|
||||
required: true
|
||||
type: str
|
||||
stack_slugs:
|
||||
description:
|
||||
- A list of Stack slugs to query instances in. If no entry then get instances in all stacks on the account.
|
||||
type: list
|
||||
elements: str
|
||||
use_internal_ip:
|
||||
description:
|
||||
- Whether or not to use internal IP addresses, If false, uses external IP addresses, internal otherwise.
|
||||
- If an instance doesn't have an external IP it will not be returned when this option is set to false.
|
||||
type: bool
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
plugin: community.general.stackpath_compute
|
||||
client_id: my_client_id
|
||||
client_secret: my_client_secret
|
||||
stack_slugs:
|
||||
- my_first_stack_slug
|
||||
- my_other_stack_slug
|
||||
use_internal_ip: false
|
||||
"""
|
||||
|
||||
import traceback
|
||||
import json
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.plugins.inventory import (
|
||||
BaseInventoryPlugin,
|
||||
Constructable,
|
||||
Cacheable
|
||||
)
|
||||
from ansible.utils.display import Display
|
||||
|
||||
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
||||
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
|
||||
NAME = 'community.general.stackpath_compute'
|
||||
|
||||
def __init__(self):
|
||||
super(InventoryModule, self).__init__()
|
||||
|
||||
# credentials
|
||||
self.client_id = None
|
||||
self.client_secret = None
|
||||
self.stack_slug = None
|
||||
self.api_host = "https://gateway.stackpath.com"
|
||||
self.group_keys = [
|
||||
"stackSlug",
|
||||
"workloadId",
|
||||
"cityCode",
|
||||
"countryCode",
|
||||
"continent",
|
||||
"target",
|
||||
"name",
|
||||
"workloadSlug"
|
||||
]
|
||||
|
||||
def _validate_config(self, config):
|
||||
if config['plugin'] != 'community.general.stackpath_compute':
|
||||
raise AnsibleError("plugin doesn't match this plugin")
|
||||
try:
|
||||
client_id = config['client_id']
|
||||
if len(client_id) != 32:
|
||||
raise AnsibleError("client_id must be 32 characters long")
|
||||
except KeyError:
|
||||
raise AnsibleError("config missing client_id, a required option")
|
||||
try:
|
||||
client_secret = config['client_secret']
|
||||
if len(client_secret) != 64:
|
||||
raise AnsibleError("client_secret must be 64 characters long")
|
||||
except KeyError:
|
||||
raise AnsibleError("config missing client_id, a required option")
|
||||
return True
|
||||
|
||||
def _set_credentials(self):
|
||||
'''
|
||||
:param config_data: contents of the inventory config file
|
||||
'''
|
||||
self.client_id = self.get_option('client_id')
|
||||
self.client_secret = self.get_option('client_secret')
|
||||
|
||||
def _authenticate(self):
|
||||
payload = json.dumps(
|
||||
{
|
||||
"client_id": self.client_id,
|
||||
"client_secret": self.client_secret,
|
||||
"grant_type": "client_credentials",
|
||||
}
|
||||
)
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
resp = open_url(
|
||||
f"{self.api_host}/identity/v1/oauth2/token",
|
||||
headers=headers,
|
||||
data=payload,
|
||||
method="POST"
|
||||
)
|
||||
status_code = resp.code
|
||||
if status_code == 200:
|
||||
body = resp.read()
|
||||
self.auth_token = json.loads(body)["access_token"]
|
||||
|
||||
def _query(self):
|
||||
results = []
|
||||
workloads = []
|
||||
self._authenticate()
|
||||
for stack_slug in self.stack_slugs:
|
||||
try:
|
||||
workloads = self._stackpath_query_get_list(f"{self.api_host}/workload/v1/stacks/{stack_slug}/workloads")
|
||||
except Exception:
|
||||
raise AnsibleError(f"Failed to get workloads from the StackPath API: {traceback.format_exc()}")
|
||||
for workload in workloads:
|
||||
try:
|
||||
workload_instances = self._stackpath_query_get_list(
|
||||
f"{self.api_host}/workload/v1/stacks/{stack_slug}/workloads/{workload['id']}/instances"
|
||||
)
|
||||
except Exception:
|
||||
raise AnsibleError(f"Failed to get workload instances from the StackPath API: {traceback.format_exc()}")
|
||||
for instance in workload_instances:
|
||||
if instance["phase"] == "RUNNING":
|
||||
instance["stackSlug"] = stack_slug
|
||||
instance["workloadId"] = workload["id"]
|
||||
instance["workloadSlug"] = workload["slug"]
|
||||
instance["cityCode"] = instance["location"]["cityCode"]
|
||||
instance["countryCode"] = instance["location"]["countryCode"]
|
||||
instance["continent"] = instance["location"]["continent"]
|
||||
instance["target"] = instance["metadata"]["labels"]["workload.platform.stackpath.net/target-name"]
|
||||
try:
|
||||
if instance[self.hostname_key]:
|
||||
results.append(instance)
|
||||
except KeyError:
|
||||
pass
|
||||
return results
|
||||
|
||||
def _populate(self, instances):
|
||||
for instance in instances:
|
||||
for group_key in self.group_keys:
|
||||
group = f"{group_key}_{instance[group_key]}"
|
||||
group = group.lower().replace(" ", "_").replace("-", "_")
|
||||
self.inventory.add_group(group)
|
||||
self.inventory.add_host(instance[self.hostname_key],
|
||||
group=group)
|
||||
|
||||
def _stackpath_query_get_list(self, url):
|
||||
self._authenticate()
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {self.auth_token}",
|
||||
}
|
||||
next_page = True
|
||||
result = []
|
||||
cursor = '-1'
|
||||
while next_page:
|
||||
resp = open_url(
|
||||
f"{url}?page_request.first=10&page_request.after={cursor}",
|
||||
headers=headers,
|
||||
method="GET"
|
||||
)
|
||||
status_code = resp.code
|
||||
if status_code == 200:
|
||||
body = resp.read()
|
||||
body_json = json.loads(body)
|
||||
result.extend(body_json["results"])
|
||||
next_page = body_json["pageInfo"]["hasNextPage"]
|
||||
if next_page:
|
||||
cursor = body_json["pageInfo"]["endCursor"]
|
||||
return result
|
||||
|
||||
def _get_stack_slugs(self, stacks):
|
||||
self.stack_slugs = [stack["slug"] for stack in stacks]
|
||||
|
||||
def verify_file(self, path):
|
||||
'''
|
||||
:param loader: an ansible.parsing.dataloader.DataLoader object
|
||||
:param path: the path to the inventory config file
|
||||
:return the contents of the config file
|
||||
'''
|
||||
if super(InventoryModule, self).verify_file(path):
|
||||
if path.endswith(('stackpath_compute.yml', 'stackpath_compute.yaml')):
|
||||
return True
|
||||
display.debug(
|
||||
"stackpath_compute inventory filename must end with \
|
||||
'stackpath_compute.yml' or 'stackpath_compute.yaml'"
|
||||
)
|
||||
return False
|
||||
|
||||
def parse(self, inventory, loader, path, cache=True):
|
||||
|
||||
super(InventoryModule, self).parse(inventory, loader, path)
|
||||
|
||||
config = self._read_config_data(path)
|
||||
self._validate_config(config)
|
||||
self._set_credentials()
|
||||
|
||||
# get user specifications
|
||||
self.use_internal_ip = self.get_option('use_internal_ip')
|
||||
if self.use_internal_ip:
|
||||
self.hostname_key = "ipAddress"
|
||||
else:
|
||||
self.hostname_key = "externalIpAddress"
|
||||
|
||||
self.stack_slugs = self.get_option('stack_slugs')
|
||||
if not self.stack_slugs:
|
||||
try:
|
||||
stacks = self._stackpath_query_get_list(f"{self.api_host}/stack/v1/stacks")
|
||||
self._get_stack_slugs(stacks)
|
||||
except Exception:
|
||||
raise AnsibleError(f"Failed to get stack IDs from the Stackpath API: {traceback.format_exc()}")
|
||||
|
||||
cache_key = self.get_cache_key(path)
|
||||
# false when refresh_cache or --flush-cache is used
|
||||
if cache:
|
||||
# get the user-specified directive
|
||||
cache = self.get_option('cache')
|
||||
|
||||
# Generate inventory
|
||||
cache_needs_update = False
|
||||
if cache:
|
||||
try:
|
||||
results = self._cache[cache_key]
|
||||
except KeyError:
|
||||
# if cache expires or cache file doesn't exist
|
||||
cache_needs_update = True
|
||||
|
||||
if not cache or cache_needs_update:
|
||||
results = self._query()
|
||||
|
||||
self._populate(make_unsafe(results))
|
||||
|
||||
# If the cache has expired/doesn't exist or
|
||||
# if refresh_inventory/flush cache is used
|
||||
# when the user is using caching, update the cached inventory
|
||||
try:
|
||||
if cache_needs_update or (not cache and self.get_option('cache')):
|
||||
self._cache[cache_key] = results
|
||||
except Exception:
|
||||
raise AnsibleError(f"Failed to populate data: {traceback.format_exc()}")
|
||||
@@ -66,7 +66,13 @@ class LookupModule(LookupBase):
|
||||
"""
|
||||
results = []
|
||||
for x in terms:
|
||||
results.append(listify_lookup_plugin_terms(x, templar=self._templar))
|
||||
try:
|
||||
intermediate = listify_lookup_plugin_terms(x, templar=self._templar)
|
||||
except TypeError:
|
||||
# The loader argument is deprecated in ansible-core 2.14+. Fall back to
|
||||
# pre-2.14 behavior for older ansible-core versions.
|
||||
intermediate = listify_lookup_plugin_terms(x, templar=self._templar, loader=self._loader)
|
||||
results.append(intermediate)
|
||||
return results
|
||||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
@@ -124,8 +124,11 @@ from ansible.errors import AnsibleLookupError
|
||||
from ansible.module_utils.common._collections_compat import Mapping, Sequence
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.release import __version__ as ansible_version
|
||||
from ansible.template import Templar
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
try:
|
||||
from ansible.template import trust_as_template as _trust_as_template
|
||||
HAS_DATATAGGING = True
|
||||
@@ -133,6 +136,11 @@ except ImportError:
|
||||
HAS_DATATAGGING = False
|
||||
|
||||
|
||||
# Whether Templar has a cache, which can be controlled by Templar.template()'s cache option.
|
||||
# The cache was removed for ansible-core 2.14 (https://github.com/ansible/ansible/pull/78419)
|
||||
_TEMPLAR_HAS_TEMPLATE_CACHE = LooseVersion(ansible_version) < LooseVersion('2.14.0')
|
||||
|
||||
|
||||
def _make_safe(value):
|
||||
if HAS_DATATAGGING and isinstance(value, str):
|
||||
return _trust_as_template(value)
|
||||
@@ -148,6 +156,8 @@ class LookupModule(LookupBase):
|
||||
"""
|
||||
templar.available_variables = variables or {}
|
||||
quoted_expression = "{0}{1}{2}".format("{{", expression, "}}")
|
||||
if _TEMPLAR_HAS_TEMPLATE_CACHE:
|
||||
return templar.template(quoted_expression, cache=False)
|
||||
if hasattr(templar, 'evaluate_expression'):
|
||||
# This is available since the Data Tagging PR has been merged
|
||||
return templar.evaluate_expression(_make_safe(expression))
|
||||
@@ -197,7 +207,10 @@ class LookupModule(LookupBase):
|
||||
|
||||
result = []
|
||||
if len(terms) > 0:
|
||||
templar = Templar(loader=self._templar._loader)
|
||||
if HAS_DATATAGGING:
|
||||
templar = self._templar.copy_with_new_env(available_variables={})
|
||||
else:
|
||||
templar = Templar(loader=self._templar._loader)
|
||||
data = []
|
||||
vars_so_far = set()
|
||||
for index, term in enumerate(terms):
|
||||
|
||||
@@ -67,7 +67,12 @@ class LookupModule(LookupBase):
|
||||
|
||||
if isinstance(term, string_types):
|
||||
# convert a variable to a list
|
||||
term2 = listify_lookup_plugin_terms(term, templar=self._templar)
|
||||
try:
|
||||
term2 = listify_lookup_plugin_terms(term, templar=self._templar)
|
||||
except TypeError:
|
||||
# The loader argument is deprecated in ansible-core 2.14+. Fall back to
|
||||
# pre-2.14 behavior for older ansible-core versions.
|
||||
term2 = listify_lookup_plugin_terms(term, templar=self._templar, loader=self._loader)
|
||||
# but avoid converting a plain string to a list of one string
|
||||
if term2 != [term]:
|
||||
term = term2
|
||||
|
||||
282
plugins/lookup/manifold.py
Normal file
282
plugins/lookup/manifold.py
Normal file
@@ -0,0 +1,282 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2018, Arigato Machine Inc.
|
||||
# Copyright (c) 2018, Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = '''
|
||||
author:
|
||||
- Kyrylo Galanov (!UNKNOWN) <galanoff@gmail.com>
|
||||
name: manifold
|
||||
short_description: get credentials from Manifold.co
|
||||
description:
|
||||
- Retrieves resources' credentials from Manifold.co
|
||||
deprecated:
|
||||
removed_in: 11.0.0
|
||||
why: Manifold (the company) has been acquired in 2021 and the services used by this plugin are no longer operational.
|
||||
alternative: There is none.
|
||||
options:
|
||||
_terms:
|
||||
description:
|
||||
- Optional list of resource labels to lookup on Manifold.co. If no resources are specified, all
|
||||
matched resources will be returned.
|
||||
type: list
|
||||
elements: string
|
||||
required: false
|
||||
api_token:
|
||||
description:
|
||||
- manifold API token
|
||||
type: string
|
||||
required: true
|
||||
env:
|
||||
- name: MANIFOLD_API_TOKEN
|
||||
project:
|
||||
description:
|
||||
- The project label you want to get the resource for.
|
||||
type: string
|
||||
required: false
|
||||
team:
|
||||
description:
|
||||
- The team label you want to get the resource for.
|
||||
type: string
|
||||
required: false
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: all available resources
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('community.general.manifold', api_token='SecretToken') }}"
|
||||
- name: all available resources for a specific project in specific team
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('community.general.manifold', api_token='SecretToken', project='poject-1', team='team-2') }}"
|
||||
- name: two specific resources
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ lookup('community.general.manifold', 'resource-1', 'resource-2') }}"
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
_raw:
|
||||
description:
|
||||
- dictionary of credentials ready to be consumed as environment variables. If multiple resources define
|
||||
the same environment variable(s), the last one returned by the Manifold API will take precedence.
|
||||
type: dict
|
||||
'''
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.module_utils.urls import open_url, ConnectionError, SSLValidationError
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
from ansible.module_utils import six
|
||||
from ansible.utils.display import Display
|
||||
from traceback import format_exception
|
||||
import json
|
||||
import sys
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
class ApiError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ManifoldApiClient(object):
|
||||
http_agent = 'python-manifold-ansible-1.0.0'
|
||||
|
||||
def __init__(self, token):
|
||||
self._token = token
|
||||
|
||||
def _make_url(self, api, endpoint):
|
||||
return f'https://api.{api}.manifold.co/v1/{endpoint}'
|
||||
|
||||
def request(self, api, endpoint, *args, **kwargs):
|
||||
"""
|
||||
Send a request to API backend and pre-process a response.
|
||||
:param api: API to send a request to
|
||||
:type api: str
|
||||
:param endpoint: API endpoint to fetch data from
|
||||
:type endpoint: str
|
||||
:param args: other args for open_url
|
||||
:param kwargs: other kwargs for open_url
|
||||
:return: server response. JSON response is automatically deserialized.
|
||||
:rtype: dict | list | str
|
||||
"""
|
||||
|
||||
default_headers = {
|
||||
'Authorization': f"Bearer {self._token}",
|
||||
'Accept': "*/*" # Otherwise server doesn't set content-type header
|
||||
}
|
||||
|
||||
url = self._make_url(api, endpoint)
|
||||
|
||||
headers = default_headers
|
||||
arg_headers = kwargs.pop('headers', None)
|
||||
if arg_headers:
|
||||
headers.update(arg_headers)
|
||||
|
||||
try:
|
||||
display.vvvv(f'manifold lookup connecting to {url}')
|
||||
response = open_url(url, headers=headers, http_agent=self.http_agent, *args, **kwargs)
|
||||
data = response.read()
|
||||
if response.headers.get('content-type') == 'application/json':
|
||||
data = json.loads(data)
|
||||
return data
|
||||
except ValueError:
|
||||
raise ApiError(f'JSON response can\'t be parsed while requesting {url}:\n{data}')
|
||||
except HTTPError as e:
|
||||
raise ApiError(f'Server returned: {e} while requesting {url}:\n{e.read()}')
|
||||
except URLError as e:
|
||||
raise ApiError(f'Failed lookup url for {url} : {e}')
|
||||
except SSLValidationError as e:
|
||||
raise ApiError(f'Error validating the server\'s certificate for {url}: {e}')
|
||||
except ConnectionError as e:
|
||||
raise ApiError(f'Error connecting to {url}: {e}')
|
||||
|
||||
def get_resources(self, team_id=None, project_id=None, label=None):
|
||||
"""
|
||||
Get resources list
|
||||
:param team_id: ID of the Team to filter resources by
|
||||
:type team_id: str
|
||||
:param project_id: ID of the project to filter resources by
|
||||
:type project_id: str
|
||||
:param label: filter resources by a label, returns a list with one or zero elements
|
||||
:type label: str
|
||||
:return: list of resources
|
||||
:rtype: list
|
||||
"""
|
||||
api = 'marketplace'
|
||||
endpoint = 'resources'
|
||||
query_params = {}
|
||||
|
||||
if team_id:
|
||||
query_params['team_id'] = team_id
|
||||
if project_id:
|
||||
query_params['project_id'] = project_id
|
||||
if label:
|
||||
query_params['label'] = label
|
||||
|
||||
if query_params:
|
||||
endpoint += f"?{urlencode(query_params)}"
|
||||
|
||||
return self.request(api, endpoint)
|
||||
|
||||
def get_teams(self, label=None):
|
||||
"""
|
||||
Get teams list
|
||||
:param label: filter teams by a label, returns a list with one or zero elements
|
||||
:type label: str
|
||||
:return: list of teams
|
||||
:rtype: list
|
||||
"""
|
||||
api = 'identity'
|
||||
endpoint = 'teams'
|
||||
data = self.request(api, endpoint)
|
||||
# Label filtering is not supported by API, however this function provides uniform interface
|
||||
if label:
|
||||
data = list(filter(lambda x: x['body']['label'] == label, data))
|
||||
return data
|
||||
|
||||
def get_projects(self, label=None):
|
||||
"""
|
||||
Get projects list
|
||||
:param label: filter projects by a label, returns a list with one or zero elements
|
||||
:type label: str
|
||||
:return: list of projects
|
||||
:rtype: list
|
||||
"""
|
||||
api = 'marketplace'
|
||||
endpoint = 'projects'
|
||||
query_params = {}
|
||||
|
||||
if label:
|
||||
query_params['label'] = label
|
||||
|
||||
if query_params:
|
||||
endpoint += f"?{urlencode(query_params)}"
|
||||
|
||||
return self.request(api, endpoint)
|
||||
|
||||
def get_credentials(self, resource_id):
|
||||
"""
|
||||
Get resource credentials
|
||||
:param resource_id: ID of the resource to filter credentials by
|
||||
:type resource_id: str
|
||||
:return:
|
||||
"""
|
||||
api = 'marketplace'
|
||||
endpoint = f"credentials?{urlencode({'resource_id': resource_id})}"
|
||||
return self.request(api, endpoint)
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
"""
|
||||
:param terms: a list of resources lookups to run.
|
||||
:param variables: ansible variables active at the time of the lookup
|
||||
:param api_token: API token
|
||||
:param project: optional project label
|
||||
:param team: optional team label
|
||||
:return: a dictionary of resources credentials
|
||||
"""
|
||||
|
||||
self.set_options(var_options=variables, direct=kwargs)
|
||||
|
||||
api_token = self.get_option('api_token')
|
||||
project = self.get_option('project')
|
||||
team = self.get_option('team')
|
||||
|
||||
try:
|
||||
labels = terms
|
||||
client = ManifoldApiClient(api_token)
|
||||
|
||||
if team:
|
||||
team_data = client.get_teams(team)
|
||||
if len(team_data) == 0:
|
||||
raise AnsibleError(f"Team '{team}' does not exist")
|
||||
team_id = team_data[0]['id']
|
||||
else:
|
||||
team_id = None
|
||||
|
||||
if project:
|
||||
project_data = client.get_projects(project)
|
||||
if len(project_data) == 0:
|
||||
raise AnsibleError(f"Project '{project}' does not exist")
|
||||
project_id = project_data[0]['id']
|
||||
else:
|
||||
project_id = None
|
||||
|
||||
if len(labels) == 1: # Use server-side filtering if one resource is requested
|
||||
resources_data = client.get_resources(team_id=team_id, project_id=project_id, label=labels[0])
|
||||
else: # Get all resources and optionally filter labels
|
||||
resources_data = client.get_resources(team_id=team_id, project_id=project_id)
|
||||
if labels:
|
||||
resources_data = list(filter(lambda x: x['body']['label'] in labels, resources_data))
|
||||
|
||||
if labels and len(resources_data) < len(labels):
|
||||
fetched_labels = [r['body']['label'] for r in resources_data]
|
||||
not_found_labels = [label for label in labels if label not in fetched_labels]
|
||||
raise AnsibleError(f"Resource(s) {', '.join(not_found_labels)} do not exist")
|
||||
|
||||
credentials = {}
|
||||
cred_map = {}
|
||||
for resource in resources_data:
|
||||
resource_credentials = client.get_credentials(resource['id'])
|
||||
if len(resource_credentials) and resource_credentials[0]['body']['values']:
|
||||
for cred_key, cred_val in six.iteritems(resource_credentials[0]['body']['values']):
|
||||
label = resource['body']['label']
|
||||
if cred_key in credentials:
|
||||
display.warning(f"'{cred_key}' with label '{cred_map[cred_key]}' was replaced by resource data with label '{label}'")
|
||||
credentials[cred_key] = cred_val
|
||||
cred_map[cred_key] = label
|
||||
|
||||
ret = [credentials]
|
||||
return ret
|
||||
except ApiError as e:
|
||||
raise AnsibleError(f'API Error: {e}')
|
||||
except AnsibleError as e:
|
||||
raise e
|
||||
except Exception:
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
raise AnsibleError(format_exception(exc_type, exc_value, exc_traceback))
|
||||
@@ -67,9 +67,11 @@ class _DjangoRunner(PythonRunner):
|
||||
|
||||
class DjangoModuleHelper(ModuleHelper):
|
||||
module = {}
|
||||
use_old_vardict = False
|
||||
django_admin_cmd = None
|
||||
arg_formats = {}
|
||||
django_admin_arg_order = ()
|
||||
use_old_vardict = False
|
||||
_django_args = []
|
||||
_check_mode_arg = ""
|
||||
|
||||
|
||||
38
plugins/module_utils/mh/mixins/deps.py
Normal file
38
plugins/module_utils/mh/mixins/deps.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# (c) 2020, Alexei Znamensky <russoz@gmail.com>
|
||||
# Copyright (c) 2020, Ansible Project
|
||||
# Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class DependencyCtxMgr(object):
|
||||
"""
|
||||
DEPRECATION WARNING
|
||||
|
||||
This class is deprecated and will be removed in community.general 11.0.0
|
||||
Modules should use plugins/module_utils/deps.py instead.
|
||||
"""
|
||||
def __init__(self, name, msg=None):
|
||||
self.name = name
|
||||
self.msg = msg
|
||||
self.has_it = False
|
||||
self.exc_type = None
|
||||
self.exc_val = None
|
||||
self.exc_tb = None
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.has_it = exc_type is None
|
||||
self.exc_type = exc_type
|
||||
self.exc_val = exc_val
|
||||
self.exc_tb = exc_tb
|
||||
return not self.has_it
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
return self.msg or str(self.exc_val)
|
||||
153
plugins/module_utils/mh/mixins/vars.py
Normal file
153
plugins/module_utils/mh/mixins/vars.py
Normal file
@@ -0,0 +1,153 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# (c) 2020, Alexei Znamensky <russoz@gmail.com>
|
||||
# Copyright (c) 2020, Ansible Project
|
||||
# Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
import copy
|
||||
|
||||
|
||||
class VarMeta(object):
|
||||
"""
|
||||
DEPRECATION WARNING
|
||||
|
||||
This class is deprecated and will be removed in community.general 11.0.0
|
||||
Modules should use the VarDict from plugins/module_utils/vardict.py instead.
|
||||
"""
|
||||
|
||||
NOTHING = object()
|
||||
|
||||
def __init__(self, diff=False, output=True, change=None, fact=False):
|
||||
self.init = False
|
||||
self.initial_value = None
|
||||
self.value = None
|
||||
|
||||
self.diff = diff
|
||||
self.change = diff if change is None else change
|
||||
self.output = output
|
||||
self.fact = fact
|
||||
|
||||
def set(self, diff=None, output=None, change=None, fact=None, initial_value=NOTHING):
|
||||
if diff is not None:
|
||||
self.diff = diff
|
||||
if output is not None:
|
||||
self.output = output
|
||||
if change is not None:
|
||||
self.change = change
|
||||
if fact is not None:
|
||||
self.fact = fact
|
||||
if initial_value is not self.NOTHING:
|
||||
self.initial_value = copy.deepcopy(initial_value)
|
||||
|
||||
def set_value(self, value):
|
||||
if not self.init:
|
||||
self.initial_value = copy.deepcopy(value)
|
||||
self.init = True
|
||||
self.value = value
|
||||
return self
|
||||
|
||||
@property
|
||||
def has_changed(self):
|
||||
return self.change and (self.initial_value != self.value)
|
||||
|
||||
@property
|
||||
def diff_result(self):
|
||||
return None if not (self.diff and self.has_changed) else {
|
||||
'before': self.initial_value,
|
||||
'after': self.value,
|
||||
}
|
||||
|
||||
def __str__(self):
|
||||
return "<VarMeta: value={0}, initial={1}, diff={2}, output={3}, change={4}>".format(
|
||||
self.value, self.initial_value, self.diff, self.output, self.change
|
||||
)
|
||||
|
||||
|
||||
class VarDict(object):
|
||||
"""
|
||||
DEPRECATION WARNING
|
||||
|
||||
This class is deprecated and will be removed in community.general 11.0.0
|
||||
Modules should use the VarDict from plugins/module_utils/vardict.py instead.
|
||||
"""
|
||||
def __init__(self):
|
||||
self._data = dict()
|
||||
self._meta = dict()
|
||||
|
||||
def __getitem__(self, item):
|
||||
return self._data[item]
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
self.set(key, value)
|
||||
|
||||
def __getattr__(self, item):
|
||||
try:
|
||||
return self._data[item]
|
||||
except KeyError:
|
||||
return getattr(self._data, item)
|
||||
|
||||
def __setattr__(self, key, value):
|
||||
if key in ('_data', '_meta'):
|
||||
super(VarDict, self).__setattr__(key, value)
|
||||
else:
|
||||
self.set(key, value)
|
||||
|
||||
def meta(self, name):
|
||||
return self._meta[name]
|
||||
|
||||
def set_meta(self, name, **kwargs):
|
||||
self.meta(name).set(**kwargs)
|
||||
|
||||
def set(self, name, value, **kwargs):
|
||||
if name in ('_data', '_meta'):
|
||||
raise ValueError("Names _data and _meta are reserved for use by ModuleHelper")
|
||||
self._data[name] = value
|
||||
if name in self._meta:
|
||||
meta = self.meta(name)
|
||||
else:
|
||||
meta = VarMeta(**kwargs)
|
||||
meta.set_value(value)
|
||||
self._meta[name] = meta
|
||||
|
||||
def output(self):
|
||||
return {k: v for k, v in self._data.items() if self.meta(k).output}
|
||||
|
||||
def diff(self):
|
||||
diff_results = [(k, self.meta(k).diff_result) for k in self._data]
|
||||
diff_results = [dr for dr in diff_results if dr[1] is not None]
|
||||
if diff_results:
|
||||
before = dict((dr[0], dr[1]['before']) for dr in diff_results)
|
||||
after = dict((dr[0], dr[1]['after']) for dr in diff_results)
|
||||
return {'before': before, 'after': after}
|
||||
return None
|
||||
|
||||
def facts(self):
|
||||
facts_result = {k: v for k, v in self._data.items() if self._meta[k].fact}
|
||||
return facts_result if facts_result else None
|
||||
|
||||
def change_vars(self):
|
||||
return [v for v in self._data if self.meta(v).change]
|
||||
|
||||
def has_changed(self, v):
|
||||
return self._meta[v].has_changed
|
||||
|
||||
|
||||
class VarsMixin(object):
|
||||
"""
|
||||
DEPRECATION WARNING
|
||||
|
||||
This class is deprecated and will be removed in community.general 11.0.0
|
||||
Modules should use the VarDict from plugins/module_utils/vardict.py instead.
|
||||
"""
|
||||
def __init__(self, module=None):
|
||||
self.vars = VarDict()
|
||||
super(VarsMixin, self).__init__(module)
|
||||
|
||||
def update_vars(self, meta=None, **kwargs):
|
||||
if meta is None:
|
||||
meta = {}
|
||||
for k, v in kwargs.items():
|
||||
self.vars.set(k, v, **meta)
|
||||
@@ -10,9 +10,13 @@ __metaclass__ = type
|
||||
|
||||
from ansible.module_utils.common.dict_transformations import dict_merge
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.vardict import VarDict
|
||||
from ansible_collections.community.general.plugins.module_utils.vardict import VarDict as _NewVarDict # remove "as NewVarDict" in 11.0.0
|
||||
# (TODO: remove AnsibleModule!) pylint: disable-next=unused-import
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.base import AnsibleModule # noqa: F401 DEPRECATED, remove in 11.0.0
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.base import ModuleHelperBase
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.mixins.state import StateMixin
|
||||
# (TODO: remove mh.mixins.vars!) pylint: disable-next=unused-import
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.mixins.vars import VarsMixin, VarDict as _OldVarDict # noqa: F401 remove in 11.0.0
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.mixins.deprecate_attrs import DeprecateAttrsMixin
|
||||
|
||||
|
||||
@@ -22,11 +26,24 @@ class ModuleHelper(DeprecateAttrsMixin, ModuleHelperBase):
|
||||
diff_params = ()
|
||||
change_params = ()
|
||||
facts_params = ()
|
||||
use_old_vardict = True # remove in 11.0.0
|
||||
mute_vardict_deprecation = False
|
||||
|
||||
def __init__(self, module=None):
|
||||
super(ModuleHelper, self).__init__(module)
|
||||
if self.use_old_vardict: # remove first half of the if in 11.0.0
|
||||
self.vars = _OldVarDict()
|
||||
super(ModuleHelper, self).__init__(module)
|
||||
if not self.mute_vardict_deprecation:
|
||||
self.module.deprecate(
|
||||
"This class is using the old VarDict from ModuleHelper, which is deprecated. "
|
||||
"Set the class variable use_old_vardict to False and make the necessary adjustments."
|
||||
"The old VarDict class will be removed in community.general 11.0.0",
|
||||
version="11.0.0", collection_name="community.general"
|
||||
)
|
||||
else:
|
||||
self.vars = _NewVarDict()
|
||||
super(ModuleHelper, self).__init__(module)
|
||||
|
||||
self.vars = VarDict()
|
||||
for name, value in self.module.params.items():
|
||||
self.vars.set(
|
||||
name, value,
|
||||
@@ -49,6 +66,9 @@ class ModuleHelper(DeprecateAttrsMixin, ModuleHelperBase):
|
||||
self.update_vars(meta={"fact": True}, **kwargs)
|
||||
|
||||
def _vars_changed(self):
|
||||
if self.use_old_vardict:
|
||||
return any(self.vars.has_changed(v) for v in self.vars.change_vars())
|
||||
|
||||
return self.vars.has_changed
|
||||
|
||||
def has_changed(self):
|
||||
|
||||
@@ -11,8 +11,12 @@ __metaclass__ = type
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.module_helper import (
|
||||
ModuleHelper, StateModuleHelper,
|
||||
AnsibleModule # remove in 11.0.0
|
||||
)
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.mixins.state import StateMixin # noqa: F401 remove in 11.0.0
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.mixins.deps import DependencyCtxMgr # noqa: F401 remove in 11.0.0
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.exceptions import ModuleHelperException # noqa: F401
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.deco import (
|
||||
cause_changes, module_fails_on_exception, check_mode_skip, check_mode_skip_returns,
|
||||
)
|
||||
from ansible_collections.community.general.plugins.module_utils.mh.mixins.vars import VarMeta, VarDict, VarsMixin # noqa: F401 remove in 11.0.0
|
||||
|
||||
@@ -37,20 +37,10 @@ def fmt_resource_argument(value):
|
||||
return ['--group' if value['argument_action'] == 'group' else value['argument_action']] + value['argument_option']
|
||||
|
||||
|
||||
def get_pacemaker_maintenance_mode(runner):
|
||||
with runner("config") as ctx:
|
||||
rc, out, err = ctx.run()
|
||||
maintenance_mode_output = list(filter(lambda string: "maintenance-mode=true" in string.lower(), out.splitlines()))
|
||||
return bool(maintenance_mode_output)
|
||||
|
||||
|
||||
def pacemaker_runner(module, cli_action=None, **kwargs):
|
||||
runner_command = ['pcs']
|
||||
if cli_action:
|
||||
runner_command.append(cli_action)
|
||||
def pacemaker_runner(module, cli_action, **kwargs):
|
||||
runner = CmdRunner(
|
||||
module,
|
||||
command=runner_command,
|
||||
command=['pcs', cli_action],
|
||||
arg_formats=dict(
|
||||
state=cmd_runner_fmt.as_map(_state_map),
|
||||
name=cmd_runner_fmt.as_list(),
|
||||
@@ -60,8 +50,6 @@ def pacemaker_runner(module, cli_action=None, **kwargs):
|
||||
resource_meta=cmd_runner_fmt.stack(cmd_runner_fmt.as_opt_val)("meta"),
|
||||
resource_argument=cmd_runner_fmt.as_func(fmt_resource_argument),
|
||||
wait=cmd_runner_fmt.as_opt_eq_val("--wait"),
|
||||
config=cmd_runner_fmt.as_fixed("config"),
|
||||
force=cmd_runner_fmt.as_bool("--force"),
|
||||
),
|
||||
**kwargs
|
||||
)
|
||||
|
||||
242
plugins/module_utils/proxmox.py
Normal file
242
plugins/module_utils/proxmox.py
Normal file
@@ -0,0 +1,242 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2020, Tristan Le Guern <tleguern at bouledef.eu>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
import traceback
|
||||
from time import sleep
|
||||
|
||||
PROXMOXER_IMP_ERR = None
|
||||
try:
|
||||
from proxmoxer import ProxmoxAPI
|
||||
from proxmoxer import __version__ as proxmoxer_version
|
||||
HAS_PROXMOXER = True
|
||||
except ImportError:
|
||||
HAS_PROXMOXER = False
|
||||
PROXMOXER_IMP_ERR = traceback.format_exc()
|
||||
|
||||
|
||||
from ansible.module_utils.basic import env_fallback, missing_required_lib
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
|
||||
def proxmox_auth_argument_spec():
|
||||
return dict(
|
||||
api_host=dict(type='str',
|
||||
required=True,
|
||||
fallback=(env_fallback, ['PROXMOX_HOST'])
|
||||
),
|
||||
api_port=dict(type='int',
|
||||
fallback=(env_fallback, ['PROXMOX_PORT'])
|
||||
),
|
||||
api_user=dict(type='str',
|
||||
required=True,
|
||||
fallback=(env_fallback, ['PROXMOX_USER'])
|
||||
),
|
||||
api_password=dict(type='str',
|
||||
no_log=True,
|
||||
fallback=(env_fallback, ['PROXMOX_PASSWORD'])
|
||||
),
|
||||
api_token_id=dict(type='str',
|
||||
no_log=False
|
||||
),
|
||||
api_token_secret=dict(type='str',
|
||||
no_log=True
|
||||
),
|
||||
validate_certs=dict(type='bool',
|
||||
default=False
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def proxmox_to_ansible_bool(value):
|
||||
'''Convert Proxmox representation of a boolean to be ansible-friendly'''
|
||||
return True if value == 1 else False
|
||||
|
||||
|
||||
def ansible_to_proxmox_bool(value):
|
||||
'''Convert Ansible representation of a boolean to be proxmox-friendly'''
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if not isinstance(value, bool):
|
||||
raise ValueError("%s must be of type bool not %s" % (value, type(value)))
|
||||
|
||||
return 1 if value else 0
|
||||
|
||||
|
||||
class ProxmoxAnsible(object):
|
||||
"""Base class for Proxmox modules"""
|
||||
TASK_TIMED_OUT = 'timeout expired'
|
||||
|
||||
def __init__(self, module):
|
||||
if not HAS_PROXMOXER:
|
||||
module.fail_json(msg=missing_required_lib('proxmoxer'), exception=PROXMOXER_IMP_ERR)
|
||||
|
||||
self.module = module
|
||||
self.proxmoxer_version = proxmoxer_version
|
||||
self.proxmox_api = self._connect()
|
||||
# Test token validity
|
||||
try:
|
||||
self.proxmox_api.version.get()
|
||||
except Exception as e:
|
||||
module.fail_json(msg='%s' % e, exception=traceback.format_exc())
|
||||
|
||||
def _connect(self):
|
||||
api_host = self.module.params['api_host']
|
||||
api_port = self.module.params['api_port']
|
||||
api_user = self.module.params['api_user']
|
||||
api_password = self.module.params['api_password']
|
||||
api_token_id = self.module.params['api_token_id']
|
||||
api_token_secret = self.module.params['api_token_secret']
|
||||
validate_certs = self.module.params['validate_certs']
|
||||
|
||||
auth_args = {'user': api_user}
|
||||
|
||||
if api_port:
|
||||
auth_args['port'] = api_port
|
||||
|
||||
if api_password:
|
||||
auth_args['password'] = api_password
|
||||
else:
|
||||
if self.proxmoxer_version < LooseVersion('1.1.0'):
|
||||
self.module.fail_json('Using "token_name" and "token_value" require proxmoxer>=1.1.0')
|
||||
auth_args['token_name'] = api_token_id
|
||||
auth_args['token_value'] = api_token_secret
|
||||
|
||||
try:
|
||||
return ProxmoxAPI(api_host, verify_ssl=validate_certs, **auth_args)
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg='%s' % e, exception=traceback.format_exc())
|
||||
|
||||
def version(self):
|
||||
try:
|
||||
apiversion = self.proxmox_api.version.get()
|
||||
return LooseVersion(apiversion['version'])
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg='Unable to retrieve Proxmox VE version: %s' % e)
|
||||
|
||||
def get_node(self, node):
|
||||
try:
|
||||
nodes = [n for n in self.proxmox_api.nodes.get() if n['node'] == node]
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg='Unable to retrieve Proxmox VE node: %s' % e)
|
||||
return nodes[0] if nodes else None
|
||||
|
||||
def get_nextvmid(self):
|
||||
try:
|
||||
return self.proxmox_api.cluster.nextid.get()
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg='Unable to retrieve next free vmid: %s' % e)
|
||||
|
||||
def get_vmid(self, name, ignore_missing=False, choose_first_if_multiple=False):
|
||||
try:
|
||||
vms = [vm['vmid'] for vm in self.proxmox_api.cluster.resources.get(type='vm') if vm.get('name') == name]
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg='Unable to retrieve list of VMs filtered by name %s: %s' % (name, e))
|
||||
|
||||
if not vms:
|
||||
if ignore_missing:
|
||||
return None
|
||||
|
||||
self.module.fail_json(msg='No VM with name %s found' % name)
|
||||
elif len(vms) > 1 and not choose_first_if_multiple:
|
||||
self.module.fail_json(msg='Multiple VMs with name %s found, provide vmid instead' % name)
|
||||
|
||||
return vms[0]
|
||||
|
||||
def get_vm(self, vmid, ignore_missing=False):
|
||||
try:
|
||||
vms = [vm for vm in self.proxmox_api.cluster.resources.get(type='vm') if vm['vmid'] == int(vmid)]
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg='Unable to retrieve list of VMs filtered by vmid %s: %s' % (vmid, e))
|
||||
|
||||
if vms:
|
||||
return vms[0]
|
||||
else:
|
||||
if ignore_missing:
|
||||
return None
|
||||
|
||||
self.module.fail_json(msg='VM with vmid %s does not exist in cluster' % vmid)
|
||||
|
||||
def api_task_ok(self, node, taskid):
|
||||
try:
|
||||
status = self.proxmox_api.nodes(node).tasks(taskid).status.get()
|
||||
return status['status'] == 'stopped' and status['exitstatus'] == 'OK'
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg='Unable to retrieve API task ID from node %s: %s' % (node, e))
|
||||
|
||||
def api_task_failed(self, node, taskid):
|
||||
""" Explicitly check if the task stops but exits with a failed status
|
||||
"""
|
||||
try:
|
||||
status = self.proxmox_api.nodes(node).tasks(taskid).status.get()
|
||||
return status['status'] == 'stopped' and status['exitstatus'] != 'OK'
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg='Unable to retrieve API task ID from node %s: %s' % (node, e))
|
||||
|
||||
def api_task_complete(self, node_name, task_id, timeout):
|
||||
"""Wait until the task stops or times out.
|
||||
|
||||
:param node_name: Proxmox node name where the task is running.
|
||||
:param task_id: ID of the running task.
|
||||
:param timeout: Timeout in seconds to wait for the task to complete.
|
||||
:return: Task completion status (True/False) and ``exitstatus`` message when status=False.
|
||||
"""
|
||||
status = {}
|
||||
while timeout:
|
||||
try:
|
||||
status = self.proxmox_api.nodes(node_name).tasks(task_id).status.get()
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg='Unable to retrieve API task ID from node %s: %s' % (node_name, e))
|
||||
|
||||
if status['status'] == 'stopped':
|
||||
if status['exitstatus'] == 'OK':
|
||||
return True, None
|
||||
else:
|
||||
return False, status['exitstatus']
|
||||
else:
|
||||
timeout -= 1
|
||||
if timeout <= 0:
|
||||
return False, ProxmoxAnsible.TASK_TIMED_OUT
|
||||
sleep(1)
|
||||
|
||||
def get_pool(self, poolid):
|
||||
"""Retrieve pool information
|
||||
|
||||
:param poolid: str - name of the pool
|
||||
:return: dict - pool information
|
||||
"""
|
||||
try:
|
||||
return self.proxmox_api.pools(poolid).get()
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg="Unable to retrieve pool %s information: %s" % (poolid, e))
|
||||
|
||||
def get_storages(self, type):
|
||||
"""Retrieve storages information
|
||||
|
||||
:param type: str, optional - type of storages
|
||||
:return: list of dicts - array of storages
|
||||
"""
|
||||
try:
|
||||
return self.proxmox_api.storage.get(type=type)
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg="Unable to retrieve storages information with type %s: %s" % (type, e))
|
||||
|
||||
def get_storage_content(self, node, storage, content=None, vmid=None):
|
||||
try:
|
||||
return (
|
||||
self.proxmox_api.nodes(node)
|
||||
.storage(storage)
|
||||
.content()
|
||||
.get(content=content, vmid=vmid)
|
||||
)
|
||||
except Exception as e:
|
||||
self.module.fail_json(
|
||||
msg="Unable to list content on %s, %s for %s and %s: %s"
|
||||
% (node, storage, content, vmid, e)
|
||||
)
|
||||
@@ -10,7 +10,9 @@ import json
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import gzip
|
||||
import time
|
||||
from io import BytesIO
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
@@ -19,6 +21,8 @@ from ansible.module_utils.six import text_type
|
||||
from ansible.module_utils.six.moves import http_client
|
||||
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
GET_HEADERS = {'accept': 'application/json', 'OData-Version': '4.0'}
|
||||
POST_HEADERS = {'content-type': 'application/json', 'accept': 'application/json',
|
||||
@@ -179,7 +183,12 @@ class RedfishUtils(object):
|
||||
timeout=timeout,
|
||||
)
|
||||
try:
|
||||
data = json.loads(to_native(resp.read()))
|
||||
if headers.get('content-encoding') == 'gzip' and LooseVersion(ansible_version) < LooseVersion('2.14'):
|
||||
# Older versions of Ansible do not automatically decompress the data
|
||||
# Starting in 2.14, open_url will decompress the response data by default
|
||||
data = json.loads(to_native(gzip.open(BytesIO(resp.read()), 'rt', encoding='utf-8').read()))
|
||||
else:
|
||||
data = json.loads(to_native(resp.read()))
|
||||
except Exception as e:
|
||||
# No response data; this is okay in certain cases
|
||||
data = None
|
||||
@@ -442,6 +451,9 @@ class RedfishUtils(object):
|
||||
pass
|
||||
return msg, data
|
||||
|
||||
def _init_session(self):
|
||||
self.module.deprecate("Method _init_session is deprecated and will be removed.", version="11.0.0", collection_name="community.general")
|
||||
|
||||
def _get_vendor(self):
|
||||
# If we got the vendor info once, don't get it again
|
||||
if self._vendor is not None:
|
||||
|
||||
@@ -150,6 +150,7 @@ class AndroidSdk(StateModuleHelper):
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
use_old_vardict = False
|
||||
|
||||
def __init_module__(self):
|
||||
self.sdkmanager = AndroidSdkManager(self.module)
|
||||
|
||||
@@ -220,6 +220,7 @@ class AnsibleGalaxyInstall(ModuleHelper):
|
||||
required_if=[('type', 'both', ['requirements_file'])],
|
||||
supports_check_mode=False,
|
||||
)
|
||||
use_old_vardict = False
|
||||
|
||||
command = 'ansible-galaxy'
|
||||
command_args_formats = dict(
|
||||
|
||||
@@ -387,6 +387,7 @@ class ApacheModProxy(ModuleHelper):
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
use_old_vardict = False
|
||||
|
||||
def __init_module__(self):
|
||||
deps.validate(self.module)
|
||||
|
||||
@@ -35,9 +35,9 @@ options:
|
||||
state:
|
||||
description:
|
||||
- Indicates the desired package state.
|
||||
- Please note that V(present) and V(installed) are equivalent to V(latest) right now. This will change in the future.
|
||||
To simply ensure that a package is installed, without upgrading it, use the V(present_not_latest) state.
|
||||
- The states V(latest) and V(present_not_latest) have been added in community.general 8.6.0.
|
||||
- Please note before community.general 11.0.0, V(present) and V(installed) were equivalent to V(latest).
|
||||
This changed in community.general 11.0.0. Now they are equivalent to V(present_not_latest).
|
||||
choices:
|
||||
- absent
|
||||
- present
|
||||
@@ -307,6 +307,17 @@ def main():
|
||||
module.fail_json(msg="cannot find /usr/bin/apt-get and/or /usr/bin/rpm")
|
||||
|
||||
p = module.params
|
||||
if p['state'] in ['installed', 'present']:
|
||||
module.deprecate(
|
||||
'state=%s currently behaves unexpectedly by always upgrading to the latest version if'
|
||||
' the package is already installed. This behavior is deprecated and will change in'
|
||||
' community.general 11.0.0. You can use state=latest to explicitly request this behavior'
|
||||
' or state=present_not_latest to explicitly request the behavior that state=%s will have'
|
||||
' in community.general 11.0.0, namely that the package will not be upgraded if it is'
|
||||
' already installed.' % (p['state'], p['state']),
|
||||
version='11.0.0',
|
||||
collection_name='community.general',
|
||||
)
|
||||
|
||||
modified = False
|
||||
output = ""
|
||||
@@ -330,7 +341,7 @@ def main():
|
||||
|
||||
packages = p['package']
|
||||
if p['state'] in ['installed', 'present', 'present_not_latest', 'latest']:
|
||||
(m, out) = install_packages(module, packages, allow_upgrade=p['state'] == 'latest')
|
||||
(m, out) = install_packages(module, packages, allow_upgrade=p['state'] != 'present_not_latest')
|
||||
modified = modified or m
|
||||
output += out
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ module: campfire
|
||||
short_description: Send a message to Campfire
|
||||
description:
|
||||
- Send a message to Campfire.
|
||||
- Messages with newlines will result in a "Paste" message being sent.
|
||||
- Messages with newlines result in a "Paste" message being sent.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
attributes:
|
||||
|
||||
@@ -40,10 +40,10 @@ options:
|
||||
choices: [absent, present]
|
||||
default: present
|
||||
notes:
|
||||
- The capabilities system will automatically transform operators and flags into the effective set, so for example, C(cap_foo=ep)
|
||||
will probably become C(cap_foo+ep).
|
||||
- This module does not attempt to determine the final operator and flags to compare, so you will want to ensure that your
|
||||
capabilities argument matches the final capabilities.
|
||||
- The capabilities system automatically transforms operators and flags into the effective set, so for example, C(cap_foo=ep)
|
||||
probably becomes C(cap_foo+ep).
|
||||
- This module does not attempt to determine the final operator and flags to compare, so you want to ensure that your capabilities
|
||||
argument matches the final capabilities.
|
||||
author:
|
||||
- Nate Coraor (@natefoo)
|
||||
"""
|
||||
|
||||
@@ -28,7 +28,7 @@ options:
|
||||
executable:
|
||||
description:
|
||||
- Path to the C(cargo) installed in the system.
|
||||
- If not specified, the module will look C(cargo) in E(PATH).
|
||||
- If not specified, the module looks for C(cargo) in E(PATH).
|
||||
type: path
|
||||
version_added: 7.5.0
|
||||
name:
|
||||
@@ -39,11 +39,11 @@ options:
|
||||
required: true
|
||||
path:
|
||||
description: The base path where to install the Rust packages. Cargo automatically appends V(/bin). In other words, V(/usr/local)
|
||||
will become V(/usr/local/bin).
|
||||
becomes V(/usr/local/bin).
|
||||
type: path
|
||||
version:
|
||||
description: The version to install. If O(name) contains multiple values, the module will try to install all of them in
|
||||
this version.
|
||||
description: The version to install. If O(name) contains multiple values, the module tries to install all of them in this
|
||||
version.
|
||||
type: str
|
||||
required: false
|
||||
locked:
|
||||
@@ -68,15 +68,6 @@ options:
|
||||
type: path
|
||||
required: false
|
||||
version_added: 9.1.0
|
||||
features:
|
||||
description:
|
||||
- List of features to activate.
|
||||
- This is only used when installing packages.
|
||||
type: list
|
||||
elements: str
|
||||
required: false
|
||||
default: []
|
||||
version_added: 11.0.0
|
||||
requirements:
|
||||
- cargo installed
|
||||
"""
|
||||
@@ -115,12 +106,6 @@ EXAMPLES = r"""
|
||||
community.general.cargo:
|
||||
name: ludusavi
|
||||
directory: /path/to/ludusavi/source
|
||||
|
||||
- name: Install "serpl" Rust package with ast_grep feature
|
||||
community.general.cargo:
|
||||
name: serpl
|
||||
features:
|
||||
- ast_grep
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -140,7 +125,6 @@ class Cargo(object):
|
||||
self.version = kwargs["version"]
|
||||
self.locked = kwargs["locked"]
|
||||
self.directory = kwargs["directory"]
|
||||
self.features = kwargs["features"]
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
@@ -192,8 +176,6 @@ class Cargo(object):
|
||||
if self.directory:
|
||||
cmd.append("--path")
|
||||
cmd.append(self.directory)
|
||||
if self.features:
|
||||
cmd += ["--features", ",".join(self.features)]
|
||||
return self._exec(cmd)
|
||||
|
||||
def is_outdated(self, name):
|
||||
@@ -254,7 +236,6 @@ def main():
|
||||
version=dict(default=None, type="str"),
|
||||
locked=dict(default=False, type="bool"),
|
||||
directory=dict(default=None, type="path"),
|
||||
features=dict(default=[], required=False, type="list", elements="str"),
|
||||
)
|
||||
module = AnsibleModule(argument_spec=arg_spec, supports_check_mode=True)
|
||||
|
||||
|
||||
338
plugins/modules/clc_aa_policy.py
Normal file
338
plugins/modules/clc_aa_policy.py
Normal file
@@ -0,0 +1,338 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2015 CenturyLink
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: clc_aa_policy
|
||||
short_description: Create or Delete Anti-Affinity Policies at CenturyLink Cloud
|
||||
description:
|
||||
- An Ansible module to Create or Delete Anti-Affinity Policies at CenturyLink Cloud.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
- community.general.clc
|
||||
author:
|
||||
- "CLC Runner (@clc-runner)"
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
options:
|
||||
name:
|
||||
description:
|
||||
- The name of the Anti-Affinity Policy.
|
||||
type: str
|
||||
required: true
|
||||
location:
|
||||
description:
|
||||
- Datacenter in which the policy lives/should live.
|
||||
type: str
|
||||
required: true
|
||||
state:
|
||||
description:
|
||||
- Whether to create or delete the policy.
|
||||
type: str
|
||||
required: false
|
||||
default: present
|
||||
choices: ['present', 'absent']
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Create AA Policy
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Create an Anti Affinity Policy
|
||||
community.general.clc_aa_policy:
|
||||
name: Hammer Time
|
||||
location: UK3
|
||||
state: present
|
||||
register: policy
|
||||
|
||||
- name: Debug
|
||||
ansible.builtin.debug:
|
||||
var: policy
|
||||
|
||||
- name: Delete AA Policy
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Delete an Anti Affinity Policy
|
||||
community.general.clc_aa_policy:
|
||||
name: Hammer Time
|
||||
location: UK3
|
||||
state: absent
|
||||
register: policy
|
||||
|
||||
- name: Debug
|
||||
ansible.builtin.debug:
|
||||
var: policy
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
policy:
|
||||
description: The anti-affinity policy information.
|
||||
returned: success
|
||||
type: dict
|
||||
sample:
|
||||
{
|
||||
"id":"1a28dd0988984d87b9cd61fa8da15424",
|
||||
"name":"test_aa_policy",
|
||||
"location":"UC1",
|
||||
"links":[
|
||||
{
|
||||
"rel":"self",
|
||||
"href":"/v2/antiAffinityPolicies/wfad/1a28dd0988984d87b9cd61fa8da15424",
|
||||
"verbs":[
|
||||
"GET",
|
||||
"DELETE",
|
||||
"PUT"
|
||||
]
|
||||
},
|
||||
{
|
||||
"rel":"location",
|
||||
"href":"/v2/datacenters/wfad/UC1",
|
||||
"id":"uc1",
|
||||
"name":"UC1 - US West (Santa Clara)"
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
__version__ = '${version}'
|
||||
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
REQUESTS_IMP_ERR = None
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
REQUESTS_IMP_ERR = traceback.format_exc()
|
||||
REQUESTS_FOUND = False
|
||||
else:
|
||||
REQUESTS_FOUND = True
|
||||
|
||||
#
|
||||
# Requires the clc-python-sdk:
|
||||
# sudo pip install clc-sdk
|
||||
#
|
||||
CLC_IMP_ERR = None
|
||||
try:
|
||||
import clc as clc_sdk
|
||||
from clc import CLCException
|
||||
except ImportError:
|
||||
CLC_IMP_ERR = traceback.format_exc()
|
||||
CLC_FOUND = False
|
||||
clc_sdk = None
|
||||
else:
|
||||
CLC_FOUND = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
|
||||
class ClcAntiAffinityPolicy:
|
||||
|
||||
clc = clc_sdk
|
||||
module = None
|
||||
|
||||
def __init__(self, module):
|
||||
"""
|
||||
Construct module
|
||||
"""
|
||||
self.module = module
|
||||
self.policy_dict = {}
|
||||
|
||||
if not CLC_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('clc-sdk'),
|
||||
exception=CLC_IMP_ERR)
|
||||
if not REQUESTS_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('requests'),
|
||||
exception=REQUESTS_IMP_ERR)
|
||||
if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'):
|
||||
self.module.fail_json(
|
||||
msg='requests library version should be >= 2.5.0')
|
||||
|
||||
self._set_user_agent(self.clc)
|
||||
|
||||
@staticmethod
|
||||
def _define_module_argument_spec():
|
||||
"""
|
||||
Define the argument spec for the ansible module
|
||||
:return: argument spec dictionary
|
||||
"""
|
||||
argument_spec = dict(
|
||||
name=dict(required=True),
|
||||
location=dict(required=True),
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
)
|
||||
return argument_spec
|
||||
|
||||
# Module Behavior Goodness
|
||||
def process_request(self):
|
||||
"""
|
||||
Process the request - Main Code Path
|
||||
:return: Returns with either an exit_json or fail_json
|
||||
"""
|
||||
p = self.module.params
|
||||
|
||||
self._set_clc_credentials_from_env()
|
||||
self.policy_dict = self._get_policies_for_datacenter(p)
|
||||
|
||||
if p['state'] == "absent":
|
||||
changed, policy = self._ensure_policy_is_absent(p)
|
||||
else:
|
||||
changed, policy = self._ensure_policy_is_present(p)
|
||||
|
||||
if hasattr(policy, 'data'):
|
||||
policy = policy.data
|
||||
elif hasattr(policy, '__dict__'):
|
||||
policy = policy.__dict__
|
||||
|
||||
self.module.exit_json(changed=changed, policy=policy)
|
||||
|
||||
def _set_clc_credentials_from_env(self):
|
||||
"""
|
||||
Set the CLC Credentials on the sdk by reading environment variables
|
||||
:return: none
|
||||
"""
|
||||
env = os.environ
|
||||
v2_api_token = env.get('CLC_V2_API_TOKEN', False)
|
||||
v2_api_username = env.get('CLC_V2_API_USERNAME', False)
|
||||
v2_api_passwd = env.get('CLC_V2_API_PASSWD', False)
|
||||
clc_alias = env.get('CLC_ACCT_ALIAS', False)
|
||||
api_url = env.get('CLC_V2_API_URL', False)
|
||||
|
||||
if api_url:
|
||||
self.clc.defaults.ENDPOINT_URL_V2 = api_url
|
||||
|
||||
if v2_api_token and clc_alias:
|
||||
self.clc._LOGIN_TOKEN_V2 = v2_api_token
|
||||
self.clc._V2_ENABLED = True
|
||||
self.clc.ALIAS = clc_alias
|
||||
elif v2_api_username and v2_api_passwd:
|
||||
self.clc.v2.SetCredentials(
|
||||
api_username=v2_api_username,
|
||||
api_passwd=v2_api_passwd)
|
||||
else:
|
||||
return self.module.fail_json(
|
||||
msg="You must set the CLC_V2_API_USERNAME and CLC_V2_API_PASSWD "
|
||||
"environment variables")
|
||||
|
||||
def _get_policies_for_datacenter(self, p):
|
||||
"""
|
||||
Get the Policies for a datacenter by calling the CLC API.
|
||||
:param p: datacenter to get policies from
|
||||
:return: policies in the datacenter
|
||||
"""
|
||||
response = {}
|
||||
|
||||
policies = self.clc.v2.AntiAffinity.GetAll(location=p['location'])
|
||||
|
||||
for policy in policies:
|
||||
response[policy.name] = policy
|
||||
return response
|
||||
|
||||
def _create_policy(self, p):
|
||||
"""
|
||||
Create an Anti Affinity Policy using the CLC API.
|
||||
:param p: datacenter to create policy in
|
||||
:return: response dictionary from the CLC API.
|
||||
"""
|
||||
try:
|
||||
return self.clc.v2.AntiAffinity.Create(
|
||||
name=p['name'],
|
||||
location=p['location'])
|
||||
except CLCException as ex:
|
||||
self.module.fail_json(msg='Failed to create anti affinity policy : {0}. {1}'.format(
|
||||
p['name'], ex.response_text
|
||||
))
|
||||
|
||||
def _delete_policy(self, p):
|
||||
"""
|
||||
Delete an Anti Affinity Policy using the CLC API.
|
||||
:param p: datacenter to delete a policy from
|
||||
:return: none
|
||||
"""
|
||||
try:
|
||||
policy = self.policy_dict[p['name']]
|
||||
policy.Delete()
|
||||
except CLCException as ex:
|
||||
self.module.fail_json(msg='Failed to delete anti affinity policy : {0}. {1}'.format(
|
||||
p['name'], ex.response_text
|
||||
))
|
||||
|
||||
def _policy_exists(self, policy_name):
|
||||
"""
|
||||
Check to see if an Anti Affinity Policy exists
|
||||
:param policy_name: name of the policy
|
||||
:return: boolean of if the policy exists
|
||||
"""
|
||||
if policy_name in self.policy_dict:
|
||||
return self.policy_dict.get(policy_name)
|
||||
|
||||
return False
|
||||
|
||||
def _ensure_policy_is_absent(self, p):
|
||||
"""
|
||||
Makes sure that a policy is absent
|
||||
:param p: dictionary of policy name
|
||||
:return: tuple of if a deletion occurred and the name of the policy that was deleted
|
||||
"""
|
||||
changed = False
|
||||
if self._policy_exists(policy_name=p['name']):
|
||||
changed = True
|
||||
if not self.module.check_mode:
|
||||
self._delete_policy(p)
|
||||
return changed, None
|
||||
|
||||
def _ensure_policy_is_present(self, p):
|
||||
"""
|
||||
Ensures that a policy is present
|
||||
:param p: dictionary of a policy name
|
||||
:return: tuple of if an addition occurred and the name of the policy that was added
|
||||
"""
|
||||
changed = False
|
||||
policy = self._policy_exists(policy_name=p['name'])
|
||||
if not policy:
|
||||
changed = True
|
||||
policy = None
|
||||
if not self.module.check_mode:
|
||||
policy = self._create_policy(p)
|
||||
return changed, policy
|
||||
|
||||
@staticmethod
|
||||
def _set_user_agent(clc):
|
||||
if hasattr(clc, 'SetRequestsSession'):
|
||||
agent_string = "ClcAnsibleModule/" + __version__
|
||||
ses = requests.Session()
|
||||
ses.headers.update({"Api-Client": agent_string})
|
||||
ses.headers['User-Agent'] += " " + agent_string
|
||||
clc.SetRequestsSession(ses)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
The main function. Instantiates the module and calls process_request.
|
||||
:return: none
|
||||
"""
|
||||
module = AnsibleModule(
|
||||
argument_spec=ClcAntiAffinityPolicy._define_module_argument_spec(),
|
||||
supports_check_mode=True)
|
||||
clc_aa_policy = ClcAntiAffinityPolicy(module)
|
||||
clc_aa_policy.process_request()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
522
plugins/modules/clc_alert_policy.py
Normal file
522
plugins/modules/clc_alert_policy.py
Normal file
@@ -0,0 +1,522 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2015 CenturyLink
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: clc_alert_policy
|
||||
short_description: Create or Delete Alert Policies at CenturyLink Cloud
|
||||
description:
|
||||
- An Ansible module to Create or Delete Alert Policies at CenturyLink Cloud.
|
||||
deprecated:
|
||||
removed_in: 11.0.0
|
||||
why: >
|
||||
Lumen Public Cloud (formerly known as CenturyLink Cloud) has gone End-of-Life in September 2023.
|
||||
See more at U(https://www.ctl.io/knowledge-base/release-notes/2023/lumen-public-cloud-platform-end-of-life-notice/?).
|
||||
alternative: There is none.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
- community.general.clc
|
||||
author:
|
||||
- "CLC Runner (@clc-runner)"
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
options:
|
||||
alias:
|
||||
description:
|
||||
- The alias of your CLC Account.
|
||||
type: str
|
||||
required: true
|
||||
name:
|
||||
description:
|
||||
- The name of the alert policy. This is mutually exclusive with O(id).
|
||||
type: str
|
||||
id:
|
||||
description:
|
||||
- The alert policy ID. This is mutually exclusive with O(name).
|
||||
type: str
|
||||
alert_recipients:
|
||||
description:
|
||||
- A list of recipient email IDs to notify the alert. This is required for O(state=present).
|
||||
type: list
|
||||
elements: str
|
||||
metric:
|
||||
description:
|
||||
- The metric on which to measure the condition that will trigger the alert. This is required for O(state=present).
|
||||
type: str
|
||||
choices: ['cpu', 'memory', 'disk']
|
||||
duration:
|
||||
description:
|
||||
- The length of time in minutes that the condition must exceed the threshold. This is required for O(state=present).
|
||||
type: str
|
||||
threshold:
|
||||
description:
|
||||
- The threshold that will trigger the alert when the metric equals or exceeds it. This is required for O(state=present).
|
||||
This number represents a percentage and must be a value between 5.0 - 95.0 that is a multiple of 5.0.
|
||||
type: int
|
||||
state:
|
||||
description:
|
||||
- Whether to create or delete the policy.
|
||||
type: str
|
||||
default: present
|
||||
choices: ['present', 'absent']
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Create Alert Policy Example
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Create an Alert Policy for disk above 80% for 5 minutes
|
||||
community.general.clc_alert_policy:
|
||||
alias: wfad
|
||||
name: 'alert for disk > 80%'
|
||||
alert_recipients:
|
||||
- test1@centurylink.com
|
||||
- test2@centurylink.com
|
||||
metric: 'disk'
|
||||
duration: '00:05:00'
|
||||
threshold: 80
|
||||
state: present
|
||||
register: policy
|
||||
|
||||
- name: Debug
|
||||
ansible.builtin.debug: var=policy
|
||||
|
||||
- name: Delete Alert Policy Example
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Delete an Alert Policy
|
||||
community.general.clc_alert_policy:
|
||||
alias: wfad
|
||||
name: 'alert for disk > 80%'
|
||||
state: absent
|
||||
register: policy
|
||||
|
||||
- name: Debug
|
||||
ansible.builtin.debug: var=policy
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
policy:
|
||||
description: The alert policy information.
|
||||
returned: success
|
||||
type: dict
|
||||
sample:
|
||||
{
|
||||
"actions": [
|
||||
{
|
||||
"action": "email",
|
||||
"settings": {
|
||||
"recipients": [
|
||||
"user1@domain.com",
|
||||
"user1@domain.com"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"id": "ba54ac54a60d4a4f1ed6d48c1ce240a7",
|
||||
"links": [
|
||||
{
|
||||
"href": "/v2/alertPolicies/alias/ba54ac54a60d4a4fb1d6d48c1ce240a7",
|
||||
"rel": "self",
|
||||
"verbs": [
|
||||
"GET",
|
||||
"DELETE",
|
||||
"PUT"
|
||||
]
|
||||
}
|
||||
],
|
||||
"name": "test_alert",
|
||||
"triggers": [
|
||||
{
|
||||
"duration": "00:05:00",
|
||||
"metric": "disk",
|
||||
"threshold": 80.0
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
__version__ = '${version}'
|
||||
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
REQUESTS_IMP_ERR = None
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
REQUESTS_IMP_ERR = traceback.format_exc()
|
||||
REQUESTS_FOUND = False
|
||||
else:
|
||||
REQUESTS_FOUND = True
|
||||
|
||||
#
|
||||
# Requires the clc-python-sdk.
|
||||
# sudo pip install clc-sdk
|
||||
#
|
||||
CLC_IMP_ERR = None
|
||||
try:
|
||||
import clc as clc_sdk
|
||||
from clc import APIFailedResponse
|
||||
except ImportError:
|
||||
CLC_IMP_ERR = traceback.format_exc()
|
||||
CLC_FOUND = False
|
||||
clc_sdk = None
|
||||
else:
|
||||
CLC_FOUND = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
|
||||
class ClcAlertPolicy:
|
||||
|
||||
clc = clc_sdk
|
||||
module = None
|
||||
|
||||
def __init__(self, module):
|
||||
"""
|
||||
Construct module
|
||||
"""
|
||||
self.module = module
|
||||
self.policy_dict = {}
|
||||
|
||||
if not CLC_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR)
|
||||
if not REQUESTS_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR)
|
||||
if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'):
|
||||
self.module.fail_json(
|
||||
msg='requests library version should be >= 2.5.0')
|
||||
|
||||
self._set_user_agent(self.clc)
|
||||
|
||||
@staticmethod
|
||||
def _define_module_argument_spec():
|
||||
"""
|
||||
Define the argument spec for the ansible module
|
||||
:return: argument spec dictionary
|
||||
"""
|
||||
argument_spec = dict(
|
||||
name=dict(),
|
||||
id=dict(),
|
||||
alias=dict(required=True),
|
||||
alert_recipients=dict(type='list', elements='str'),
|
||||
metric=dict(
|
||||
choices=[
|
||||
'cpu',
|
||||
'memory',
|
||||
'disk']),
|
||||
duration=dict(type='str'),
|
||||
threshold=dict(type='int'),
|
||||
state=dict(default='present', choices=['present', 'absent'])
|
||||
)
|
||||
mutually_exclusive = [
|
||||
['name', 'id']
|
||||
]
|
||||
return {'argument_spec': argument_spec,
|
||||
'mutually_exclusive': mutually_exclusive}
|
||||
|
||||
# Module Behavior Goodness
|
||||
def process_request(self):
|
||||
"""
|
||||
Process the request - Main Code Path
|
||||
:return: Returns with either an exit_json or fail_json
|
||||
"""
|
||||
p = self.module.params
|
||||
|
||||
self._set_clc_credentials_from_env()
|
||||
self.policy_dict = self._get_alert_policies(p['alias'])
|
||||
|
||||
if p['state'] == 'present':
|
||||
changed, policy = self._ensure_alert_policy_is_present()
|
||||
else:
|
||||
changed, policy = self._ensure_alert_policy_is_absent()
|
||||
|
||||
self.module.exit_json(changed=changed, policy=policy)
|
||||
|
||||
def _set_clc_credentials_from_env(self):
|
||||
"""
|
||||
Set the CLC Credentials on the sdk by reading environment variables
|
||||
:return: none
|
||||
"""
|
||||
env = os.environ
|
||||
v2_api_token = env.get('CLC_V2_API_TOKEN', False)
|
||||
v2_api_username = env.get('CLC_V2_API_USERNAME', False)
|
||||
v2_api_passwd = env.get('CLC_V2_API_PASSWD', False)
|
||||
clc_alias = env.get('CLC_ACCT_ALIAS', False)
|
||||
api_url = env.get('CLC_V2_API_URL', False)
|
||||
|
||||
if api_url:
|
||||
self.clc.defaults.ENDPOINT_URL_V2 = api_url
|
||||
|
||||
if v2_api_token and clc_alias:
|
||||
self.clc._LOGIN_TOKEN_V2 = v2_api_token
|
||||
self.clc._V2_ENABLED = True
|
||||
self.clc.ALIAS = clc_alias
|
||||
elif v2_api_username and v2_api_passwd:
|
||||
self.clc.v2.SetCredentials(
|
||||
api_username=v2_api_username,
|
||||
api_passwd=v2_api_passwd)
|
||||
else:
|
||||
return self.module.fail_json(
|
||||
msg="You must set the CLC_V2_API_USERNAME and CLC_V2_API_PASSWD "
|
||||
"environment variables")
|
||||
|
||||
def _ensure_alert_policy_is_present(self):
|
||||
"""
|
||||
Ensures that the alert policy is present
|
||||
:return: (changed, policy)
|
||||
changed: A flag representing if anything is modified
|
||||
policy: the created/updated alert policy
|
||||
"""
|
||||
changed = False
|
||||
p = self.module.params
|
||||
policy_name = p.get('name')
|
||||
|
||||
if not policy_name:
|
||||
self.module.fail_json(msg='Policy name is a required')
|
||||
policy = self._alert_policy_exists(policy_name)
|
||||
if not policy:
|
||||
changed = True
|
||||
policy = None
|
||||
if not self.module.check_mode:
|
||||
policy = self._create_alert_policy()
|
||||
else:
|
||||
changed_u, policy = self._ensure_alert_policy_is_updated(policy)
|
||||
if changed_u:
|
||||
changed = True
|
||||
return changed, policy
|
||||
|
||||
def _ensure_alert_policy_is_absent(self):
|
||||
"""
|
||||
Ensures that the alert policy is absent
|
||||
:return: (changed, None)
|
||||
changed: A flag representing if anything is modified
|
||||
"""
|
||||
changed = False
|
||||
p = self.module.params
|
||||
alert_policy_id = p.get('id')
|
||||
alert_policy_name = p.get('name')
|
||||
alias = p.get('alias')
|
||||
if not alert_policy_id and not alert_policy_name:
|
||||
self.module.fail_json(
|
||||
msg='Either alert policy id or policy name is required')
|
||||
if not alert_policy_id and alert_policy_name:
|
||||
alert_policy_id = self._get_alert_policy_id(
|
||||
self.module,
|
||||
alert_policy_name)
|
||||
if alert_policy_id and alert_policy_id in self.policy_dict:
|
||||
changed = True
|
||||
if not self.module.check_mode:
|
||||
self._delete_alert_policy(alias, alert_policy_id)
|
||||
return changed, None
|
||||
|
||||
def _ensure_alert_policy_is_updated(self, alert_policy):
|
||||
"""
|
||||
Ensures the alert policy is updated if anything is changed in the alert policy configuration
|
||||
:param alert_policy: the target alert policy
|
||||
:return: (changed, policy)
|
||||
changed: A flag representing if anything is modified
|
||||
policy: the updated the alert policy
|
||||
"""
|
||||
changed = False
|
||||
p = self.module.params
|
||||
alert_policy_id = alert_policy.get('id')
|
||||
email_list = p.get('alert_recipients')
|
||||
metric = p.get('metric')
|
||||
duration = p.get('duration')
|
||||
threshold = p.get('threshold')
|
||||
policy = alert_policy
|
||||
if (metric and metric != str(alert_policy.get('triggers')[0].get('metric'))) or \
|
||||
(duration and duration != str(alert_policy.get('triggers')[0].get('duration'))) or \
|
||||
(threshold and float(threshold) != float(alert_policy.get('triggers')[0].get('threshold'))):
|
||||
changed = True
|
||||
elif email_list:
|
||||
t_email_list = list(
|
||||
alert_policy.get('actions')[0].get('settings').get('recipients'))
|
||||
if set(email_list) != set(t_email_list):
|
||||
changed = True
|
||||
if changed and not self.module.check_mode:
|
||||
policy = self._update_alert_policy(alert_policy_id)
|
||||
return changed, policy
|
||||
|
||||
def _get_alert_policies(self, alias):
|
||||
"""
|
||||
Get the alert policies for account alias by calling the CLC API.
|
||||
:param alias: the account alias
|
||||
:return: the alert policies for the account alias
|
||||
"""
|
||||
response = {}
|
||||
|
||||
policies = self.clc.v2.API.Call('GET',
|
||||
'/v2/alertPolicies/%s'
|
||||
% alias)
|
||||
|
||||
for policy in policies.get('items'):
|
||||
response[policy.get('id')] = policy
|
||||
return response
|
||||
|
||||
def _create_alert_policy(self):
|
||||
"""
|
||||
Create an alert Policy using the CLC API.
|
||||
:return: response dictionary from the CLC API.
|
||||
"""
|
||||
p = self.module.params
|
||||
alias = p['alias']
|
||||
email_list = p['alert_recipients']
|
||||
metric = p['metric']
|
||||
duration = p['duration']
|
||||
threshold = p['threshold']
|
||||
policy_name = p['name']
|
||||
arguments = json.dumps(
|
||||
{
|
||||
'name': policy_name,
|
||||
'actions': [{
|
||||
'action': 'email',
|
||||
'settings': {
|
||||
'recipients': email_list
|
||||
}
|
||||
}],
|
||||
'triggers': [{
|
||||
'metric': metric,
|
||||
'duration': duration,
|
||||
'threshold': threshold
|
||||
}]
|
||||
}
|
||||
)
|
||||
try:
|
||||
result = self.clc.v2.API.Call(
|
||||
'POST',
|
||||
'/v2/alertPolicies/%s' % alias,
|
||||
arguments)
|
||||
except APIFailedResponse as e:
|
||||
return self.module.fail_json(
|
||||
msg='Unable to create alert policy "{0}". {1}'.format(
|
||||
policy_name, str(e.response_text)))
|
||||
return result
|
||||
|
||||
def _update_alert_policy(self, alert_policy_id):
|
||||
"""
|
||||
Update alert policy using the CLC API.
|
||||
:param alert_policy_id: The clc alert policy id
|
||||
:return: response dictionary from the CLC API.
|
||||
"""
|
||||
p = self.module.params
|
||||
alias = p['alias']
|
||||
email_list = p['alert_recipients']
|
||||
metric = p['metric']
|
||||
duration = p['duration']
|
||||
threshold = p['threshold']
|
||||
policy_name = p['name']
|
||||
arguments = json.dumps(
|
||||
{
|
||||
'name': policy_name,
|
||||
'actions': [{
|
||||
'action': 'email',
|
||||
'settings': {
|
||||
'recipients': email_list
|
||||
}
|
||||
}],
|
||||
'triggers': [{
|
||||
'metric': metric,
|
||||
'duration': duration,
|
||||
'threshold': threshold
|
||||
}]
|
||||
}
|
||||
)
|
||||
try:
|
||||
result = self.clc.v2.API.Call(
|
||||
'PUT', '/v2/alertPolicies/%s/%s' %
|
||||
(alias, alert_policy_id), arguments)
|
||||
except APIFailedResponse as e:
|
||||
return self.module.fail_json(
|
||||
msg='Unable to update alert policy "{0}". {1}'.format(
|
||||
policy_name, str(e.response_text)))
|
||||
return result
|
||||
|
||||
def _delete_alert_policy(self, alias, policy_id):
|
||||
"""
|
||||
Delete an alert policy using the CLC API.
|
||||
:param alias : the account alias
|
||||
:param policy_id: the alert policy id
|
||||
:return: response dictionary from the CLC API.
|
||||
"""
|
||||
try:
|
||||
result = self.clc.v2.API.Call(
|
||||
'DELETE', '/v2/alertPolicies/%s/%s' %
|
||||
(alias, policy_id), None)
|
||||
except APIFailedResponse as e:
|
||||
return self.module.fail_json(
|
||||
msg='Unable to delete alert policy id "{0}". {1}'.format(
|
||||
policy_id, str(e.response_text)))
|
||||
return result
|
||||
|
||||
def _alert_policy_exists(self, policy_name):
|
||||
"""
|
||||
Check to see if an alert policy exists
|
||||
:param policy_name: name of the alert policy
|
||||
:return: boolean of if the policy exists
|
||||
"""
|
||||
result = False
|
||||
for policy_id in self.policy_dict:
|
||||
if self.policy_dict.get(policy_id).get('name') == policy_name:
|
||||
result = self.policy_dict.get(policy_id)
|
||||
return result
|
||||
|
||||
def _get_alert_policy_id(self, module, alert_policy_name):
|
||||
"""
|
||||
retrieves the alert policy id of the account based on the name of the policy
|
||||
:param module: the AnsibleModule object
|
||||
:param alert_policy_name: the alert policy name
|
||||
:return: alert_policy_id: The alert policy id
|
||||
"""
|
||||
alert_policy_id = None
|
||||
for policy_id in self.policy_dict:
|
||||
if self.policy_dict.get(policy_id).get('name') == alert_policy_name:
|
||||
if not alert_policy_id:
|
||||
alert_policy_id = policy_id
|
||||
else:
|
||||
return module.fail_json(
|
||||
msg='multiple alert policies were found with policy name : %s' % alert_policy_name)
|
||||
return alert_policy_id
|
||||
|
||||
@staticmethod
|
||||
def _set_user_agent(clc):
|
||||
if hasattr(clc, 'SetRequestsSession'):
|
||||
agent_string = "ClcAnsibleModule/" + __version__
|
||||
ses = requests.Session()
|
||||
ses.headers.update({"Api-Client": agent_string})
|
||||
ses.headers['User-Agent'] += " " + agent_string
|
||||
clc.SetRequestsSession(ses)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
The main function. Instantiates the module and calls process_request.
|
||||
:return: none
|
||||
"""
|
||||
argument_dict = ClcAlertPolicy._define_module_argument_spec()
|
||||
module = AnsibleModule(supports_check_mode=True, **argument_dict)
|
||||
clc_alert_policy = ClcAlertPolicy(module)
|
||||
clc_alert_policy.process_request()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
299
plugins/modules/clc_blueprint_package.py
Normal file
299
plugins/modules/clc_blueprint_package.py
Normal file
@@ -0,0 +1,299 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2015 CenturyLink
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: clc_blueprint_package
|
||||
short_description: Deploys a blue print package on a set of servers in CenturyLink Cloud
|
||||
description:
|
||||
- An Ansible module to deploy blue print package on a set of servers in CenturyLink Cloud.
|
||||
deprecated:
|
||||
removed_in: 11.0.0
|
||||
why: >
|
||||
Lumen Public Cloud (formerly known as CenturyLink Cloud) has gone End-of-Life in September 2023.
|
||||
See more at U(https://www.ctl.io/knowledge-base/release-notes/2023/lumen-public-cloud-platform-end-of-life-notice/?).
|
||||
alternative: There is none.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
- community.general.clc
|
||||
author:
|
||||
- "CLC Runner (@clc-runner)"
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
options:
|
||||
server_ids:
|
||||
description:
|
||||
- A list of server IDs to deploy the blue print package.
|
||||
type: list
|
||||
required: true
|
||||
elements: str
|
||||
package_id:
|
||||
description:
|
||||
- The package ID of the blue print.
|
||||
type: str
|
||||
required: true
|
||||
package_params:
|
||||
description:
|
||||
- The dictionary of arguments required to deploy the blue print.
|
||||
type: dict
|
||||
default: {}
|
||||
required: false
|
||||
state:
|
||||
description:
|
||||
- Whether to install or uninstall the package. Currently it supports only V(present) for install action.
|
||||
type: str
|
||||
required: false
|
||||
default: present
|
||||
choices: ['present']
|
||||
wait:
|
||||
description:
|
||||
- Whether to wait for the tasks to finish before returning.
|
||||
type: str
|
||||
default: 'True'
|
||||
required: false
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
# Note - You must set the CLC_V2_API_USERNAME And CLC_V2_API_PASSWD Environment variables before running these examples
|
||||
|
||||
- name: Deploy package
|
||||
community.general.clc_blueprint_package:
|
||||
server_ids:
|
||||
- UC1TEST-SERVER1
|
||||
- UC1TEST-SERVER2
|
||||
package_id: 77abb844-579d-478d-3955-c69ab4a7ba1a
|
||||
package_params: {}
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
server_ids:
|
||||
description: The list of server IDs that are changed.
|
||||
returned: success
|
||||
type: list
|
||||
sample: ["UC1TEST-SERVER1", "UC1TEST-SERVER2"]
|
||||
"""
|
||||
|
||||
__version__ = '${version}'
|
||||
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
REQUESTS_IMP_ERR = None
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
REQUESTS_IMP_ERR = traceback.format_exc()
|
||||
REQUESTS_FOUND = False
|
||||
else:
|
||||
REQUESTS_FOUND = True
|
||||
|
||||
#
|
||||
# Requires the clc-python-sdk.
|
||||
# sudo pip install clc-sdk
|
||||
#
|
||||
CLC_IMP_ERR = None
|
||||
try:
|
||||
import clc as clc_sdk
|
||||
from clc import CLCException
|
||||
except ImportError:
|
||||
CLC_IMP_ERR = traceback.format_exc()
|
||||
CLC_FOUND = False
|
||||
clc_sdk = None
|
||||
else:
|
||||
CLC_FOUND = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
|
||||
class ClcBlueprintPackage:
|
||||
|
||||
clc = clc_sdk
|
||||
module = None
|
||||
|
||||
def __init__(self, module):
|
||||
"""
|
||||
Construct module
|
||||
"""
|
||||
self.module = module
|
||||
if not CLC_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR)
|
||||
if not REQUESTS_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR)
|
||||
if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'):
|
||||
self.module.fail_json(
|
||||
msg='requests library version should be >= 2.5.0')
|
||||
|
||||
self._set_user_agent(self.clc)
|
||||
|
||||
def process_request(self):
|
||||
"""
|
||||
Process the request - Main Code Path
|
||||
:return: Returns with either an exit_json or fail_json
|
||||
"""
|
||||
p = self.module.params
|
||||
changed = False
|
||||
changed_server_ids = []
|
||||
self._set_clc_credentials_from_env()
|
||||
server_ids = p['server_ids']
|
||||
package_id = p['package_id']
|
||||
package_params = p['package_params']
|
||||
state = p['state']
|
||||
if state == 'present':
|
||||
changed, changed_server_ids, request_list = self.ensure_package_installed(
|
||||
server_ids, package_id, package_params)
|
||||
self._wait_for_requests_to_complete(request_list)
|
||||
self.module.exit_json(changed=changed, server_ids=changed_server_ids)
|
||||
|
||||
@staticmethod
|
||||
def define_argument_spec():
|
||||
"""
|
||||
This function defines the dictionary object required for
|
||||
package module
|
||||
:return: the package dictionary object
|
||||
"""
|
||||
argument_spec = dict(
|
||||
server_ids=dict(type='list', elements='str', required=True),
|
||||
package_id=dict(required=True),
|
||||
package_params=dict(type='dict', default={}),
|
||||
wait=dict(default=True), # @FIXME should be bool?
|
||||
state=dict(default='present', choices=['present'])
|
||||
)
|
||||
return argument_spec
|
||||
|
||||
def ensure_package_installed(self, server_ids, package_id, package_params):
|
||||
"""
|
||||
Ensure the package is installed in the given list of servers
|
||||
:param server_ids: the server list where the package needs to be installed
|
||||
:param package_id: the blueprint package id
|
||||
:param package_params: the package arguments
|
||||
:return: (changed, server_ids, request_list)
|
||||
changed: A flag indicating if a change was made
|
||||
server_ids: The list of servers modified
|
||||
request_list: The list of request objects from clc-sdk
|
||||
"""
|
||||
changed = False
|
||||
request_list = []
|
||||
servers = self._get_servers_from_clc(
|
||||
server_ids,
|
||||
'Failed to get servers from CLC')
|
||||
for server in servers:
|
||||
if not self.module.check_mode:
|
||||
request = self.clc_install_package(
|
||||
server,
|
||||
package_id,
|
||||
package_params)
|
||||
request_list.append(request)
|
||||
changed = True
|
||||
return changed, server_ids, request_list
|
||||
|
||||
def clc_install_package(self, server, package_id, package_params):
|
||||
"""
|
||||
Install the package to a given clc server
|
||||
:param server: The server object where the package needs to be installed
|
||||
:param package_id: The blue print package id
|
||||
:param package_params: the required argument dict for the package installation
|
||||
:return: The result object from the CLC API call
|
||||
"""
|
||||
result = None
|
||||
try:
|
||||
result = server.ExecutePackage(
|
||||
package_id=package_id,
|
||||
parameters=package_params)
|
||||
except CLCException as ex:
|
||||
self.module.fail_json(msg='Failed to install package : {0} to server {1}. {2}'.format(
|
||||
package_id, server.id, ex.message
|
||||
))
|
||||
return result
|
||||
|
||||
def _wait_for_requests_to_complete(self, request_lst):
|
||||
"""
|
||||
Waits until the CLC requests are complete if the wait argument is True
|
||||
:param request_lst: The list of CLC request objects
|
||||
:return: none
|
||||
"""
|
||||
if not self.module.params['wait']:
|
||||
return
|
||||
for request in request_lst:
|
||||
request.WaitUntilComplete()
|
||||
for request_details in request.requests:
|
||||
if request_details.Status() != 'succeeded':
|
||||
self.module.fail_json(
|
||||
msg='Unable to process package install request')
|
||||
|
||||
def _get_servers_from_clc(self, server_list, message):
|
||||
"""
|
||||
Internal function to fetch list of CLC server objects from a list of server ids
|
||||
:param server_list: the list of server ids
|
||||
:param message: the error message to raise if there is any error
|
||||
:return the list of CLC server objects
|
||||
"""
|
||||
try:
|
||||
return self.clc.v2.Servers(server_list).servers
|
||||
except CLCException as ex:
|
||||
self.module.fail_json(msg=message + ': %s' % ex)
|
||||
|
||||
def _set_clc_credentials_from_env(self):
|
||||
"""
|
||||
Set the CLC Credentials on the sdk by reading environment variables
|
||||
:return: none
|
||||
"""
|
||||
env = os.environ
|
||||
v2_api_token = env.get('CLC_V2_API_TOKEN', False)
|
||||
v2_api_username = env.get('CLC_V2_API_USERNAME', False)
|
||||
v2_api_passwd = env.get('CLC_V2_API_PASSWD', False)
|
||||
clc_alias = env.get('CLC_ACCT_ALIAS', False)
|
||||
api_url = env.get('CLC_V2_API_URL', False)
|
||||
|
||||
if api_url:
|
||||
self.clc.defaults.ENDPOINT_URL_V2 = api_url
|
||||
|
||||
if v2_api_token and clc_alias:
|
||||
self.clc._LOGIN_TOKEN_V2 = v2_api_token
|
||||
self.clc._V2_ENABLED = True
|
||||
self.clc.ALIAS = clc_alias
|
||||
elif v2_api_username and v2_api_passwd:
|
||||
self.clc.v2.SetCredentials(
|
||||
api_username=v2_api_username,
|
||||
api_passwd=v2_api_passwd)
|
||||
else:
|
||||
return self.module.fail_json(
|
||||
msg="You must set the CLC_V2_API_USERNAME and CLC_V2_API_PASSWD "
|
||||
"environment variables")
|
||||
|
||||
@staticmethod
|
||||
def _set_user_agent(clc):
|
||||
if hasattr(clc, 'SetRequestsSession'):
|
||||
agent_string = "ClcAnsibleModule/" + __version__
|
||||
ses = requests.Session()
|
||||
ses.headers.update({"Api-Client": agent_string})
|
||||
ses.headers['User-Agent'] += " " + agent_string
|
||||
clc.SetRequestsSession(ses)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main function
|
||||
:return: None
|
||||
"""
|
||||
module = AnsibleModule(
|
||||
argument_spec=ClcBlueprintPackage.define_argument_spec(),
|
||||
supports_check_mode=True
|
||||
)
|
||||
clc_blueprint_package = ClcBlueprintPackage(module)
|
||||
clc_blueprint_package.process_request()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
586
plugins/modules/clc_firewall_policy.py
Normal file
586
plugins/modules/clc_firewall_policy.py
Normal file
@@ -0,0 +1,586 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2015 CenturyLink
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: clc_firewall_policy
|
||||
short_description: Create/delete/update firewall policies
|
||||
description:
|
||||
- Create or delete or update firewall policies on Centurylink Cloud.
|
||||
deprecated:
|
||||
removed_in: 11.0.0
|
||||
why: >
|
||||
Lumen Public Cloud (formerly known as CenturyLink Cloud) has gone End-of-Life in September 2023.
|
||||
See more at U(https://www.ctl.io/knowledge-base/release-notes/2023/lumen-public-cloud-platform-end-of-life-notice/?).
|
||||
alternative: There is none.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
- community.general.clc
|
||||
author:
|
||||
- "CLC Runner (@clc-runner)"
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
options:
|
||||
location:
|
||||
description:
|
||||
- Target datacenter for the firewall policy.
|
||||
type: str
|
||||
required: true
|
||||
state:
|
||||
description:
|
||||
- Whether to create or delete the firewall policy.
|
||||
type: str
|
||||
default: present
|
||||
choices: ['present', 'absent']
|
||||
source:
|
||||
description:
|
||||
- The list of source addresses for traffic on the originating firewall. This is required when O(state=present).
|
||||
type: list
|
||||
elements: str
|
||||
destination:
|
||||
description:
|
||||
- The list of destination addresses for traffic on the terminating firewall. This is required when O(state=present).
|
||||
type: list
|
||||
elements: str
|
||||
ports:
|
||||
description:
|
||||
- The list of ports associated with the policy. TCP and UDP can take in single ports or port ranges.
|
||||
- "Example: V(['any', 'icmp', 'TCP/123', 'UDP/123', 'TCP/123-456', 'UDP/123-456'])."
|
||||
type: list
|
||||
elements: str
|
||||
firewall_policy_id:
|
||||
description:
|
||||
- ID of the firewall policy. This is required to update or delete an existing firewall policy.
|
||||
type: str
|
||||
source_account_alias:
|
||||
description:
|
||||
- CLC alias for the source account.
|
||||
type: str
|
||||
required: true
|
||||
destination_account_alias:
|
||||
description:
|
||||
- CLC alias for the destination account.
|
||||
type: str
|
||||
wait:
|
||||
description:
|
||||
- Whether to wait for the provisioning tasks to finish before returning.
|
||||
type: str
|
||||
default: 'True'
|
||||
enabled:
|
||||
description:
|
||||
- Whether the firewall policy is enabled or disabled.
|
||||
type: str
|
||||
choices: ['True', 'False']
|
||||
default: 'True'
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Create Firewall Policy
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Create / Verify an Firewall Policy at CenturyLink Cloud
|
||||
clc_firewall:
|
||||
source_account_alias: WFAD
|
||||
location: VA1
|
||||
state: present
|
||||
source: 10.128.216.0/24
|
||||
destination: 10.128.216.0/24
|
||||
ports: Any
|
||||
destination_account_alias: WFAD
|
||||
|
||||
- name: Delete Firewall Policy
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Delete an Firewall Policy at CenturyLink Cloud
|
||||
clc_firewall:
|
||||
source_account_alias: WFAD
|
||||
location: VA1
|
||||
state: absent
|
||||
firewall_policy_id: c62105233d7a4231bd2e91b9c791e43e1
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
firewall_policy_id:
|
||||
description: The firewall policy ID.
|
||||
returned: success
|
||||
type: str
|
||||
sample: fc36f1bfd47242e488a9c44346438c05
|
||||
firewall_policy:
|
||||
description: The firewall policy information.
|
||||
returned: success
|
||||
type: dict
|
||||
sample:
|
||||
{
|
||||
"destination":[
|
||||
"10.1.1.0/24",
|
||||
"10.2.2.0/24"
|
||||
],
|
||||
"destinationAccount":"wfad",
|
||||
"enabled":true,
|
||||
"id":"fc36f1bfd47242e488a9c44346438c05",
|
||||
"links":[
|
||||
{
|
||||
"href":"http://api.ctl.io/v2-experimental/firewallPolicies/wfad/uc1/fc36f1bfd47242e488a9c44346438c05",
|
||||
"rel":"self",
|
||||
"verbs":[
|
||||
"GET",
|
||||
"PUT",
|
||||
"DELETE"
|
||||
]
|
||||
}
|
||||
],
|
||||
"ports":[
|
||||
"any"
|
||||
],
|
||||
"source":[
|
||||
"10.1.1.0/24",
|
||||
"10.2.2.0/24"
|
||||
],
|
||||
"status":"active"
|
||||
}
|
||||
"""
|
||||
|
||||
__version__ = '${version}'
|
||||
|
||||
import os
|
||||
import traceback
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
from time import sleep
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
REQUESTS_IMP_ERR = None
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
REQUESTS_IMP_ERR = traceback.format_exc()
|
||||
REQUESTS_FOUND = False
|
||||
else:
|
||||
REQUESTS_FOUND = True
|
||||
|
||||
CLC_IMP_ERR = None
|
||||
try:
|
||||
import clc as clc_sdk
|
||||
from clc import APIFailedResponse
|
||||
except ImportError:
|
||||
CLC_IMP_ERR = traceback.format_exc()
|
||||
CLC_FOUND = False
|
||||
clc_sdk = None
|
||||
else:
|
||||
CLC_FOUND = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
|
||||
class ClcFirewallPolicy:
|
||||
|
||||
clc = None
|
||||
|
||||
def __init__(self, module):
|
||||
"""
|
||||
Construct module
|
||||
"""
|
||||
self.clc = clc_sdk
|
||||
self.module = module
|
||||
self.firewall_dict = {}
|
||||
|
||||
if not CLC_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR)
|
||||
if not REQUESTS_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR)
|
||||
if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'):
|
||||
self.module.fail_json(
|
||||
msg='requests library version should be >= 2.5.0')
|
||||
|
||||
self._set_user_agent(self.clc)
|
||||
|
||||
@staticmethod
|
||||
def _define_module_argument_spec():
|
||||
"""
|
||||
Define the argument spec for the ansible module
|
||||
:return: argument spec dictionary
|
||||
"""
|
||||
argument_spec = dict(
|
||||
location=dict(required=True),
|
||||
source_account_alias=dict(required=True),
|
||||
destination_account_alias=dict(),
|
||||
firewall_policy_id=dict(),
|
||||
ports=dict(type='list', elements='str'),
|
||||
source=dict(type='list', elements='str'),
|
||||
destination=dict(type='list', elements='str'),
|
||||
wait=dict(default=True), # @FIXME type=bool
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
enabled=dict(default=True, choices=[True, False])
|
||||
)
|
||||
return argument_spec
|
||||
|
||||
def process_request(self):
|
||||
"""
|
||||
Execute the main code path, and handle the request
|
||||
:return: none
|
||||
"""
|
||||
changed = False
|
||||
firewall_policy = None
|
||||
location = self.module.params.get('location')
|
||||
source_account_alias = self.module.params.get('source_account_alias')
|
||||
destination_account_alias = self.module.params.get(
|
||||
'destination_account_alias')
|
||||
firewall_policy_id = self.module.params.get('firewall_policy_id')
|
||||
ports = self.module.params.get('ports')
|
||||
source = self.module.params.get('source')
|
||||
destination = self.module.params.get('destination')
|
||||
wait = self.module.params.get('wait')
|
||||
state = self.module.params.get('state')
|
||||
enabled = self.module.params.get('enabled')
|
||||
|
||||
self.firewall_dict = {
|
||||
'location': location,
|
||||
'source_account_alias': source_account_alias,
|
||||
'destination_account_alias': destination_account_alias,
|
||||
'firewall_policy_id': firewall_policy_id,
|
||||
'ports': ports,
|
||||
'source': source,
|
||||
'destination': destination,
|
||||
'wait': wait,
|
||||
'state': state,
|
||||
'enabled': enabled}
|
||||
|
||||
self._set_clc_credentials_from_env()
|
||||
|
||||
if state == 'absent':
|
||||
changed, firewall_policy_id, firewall_policy = self._ensure_firewall_policy_is_absent(
|
||||
source_account_alias, location, self.firewall_dict)
|
||||
|
||||
elif state == 'present':
|
||||
changed, firewall_policy_id, firewall_policy = self._ensure_firewall_policy_is_present(
|
||||
source_account_alias, location, self.firewall_dict)
|
||||
|
||||
return self.module.exit_json(
|
||||
changed=changed,
|
||||
firewall_policy_id=firewall_policy_id,
|
||||
firewall_policy=firewall_policy)
|
||||
|
||||
@staticmethod
|
||||
def _get_policy_id_from_response(response):
|
||||
"""
|
||||
Method to parse out the policy id from creation response
|
||||
:param response: response from firewall creation API call
|
||||
:return: policy_id: firewall policy id from creation call
|
||||
"""
|
||||
url = response.get('links')[0]['href']
|
||||
path = urlparse(url).path
|
||||
path_list = os.path.split(path)
|
||||
policy_id = path_list[-1]
|
||||
return policy_id
|
||||
|
||||
def _set_clc_credentials_from_env(self):
|
||||
"""
|
||||
Set the CLC Credentials on the sdk by reading environment variables
|
||||
:return: none
|
||||
"""
|
||||
env = os.environ
|
||||
v2_api_token = env.get('CLC_V2_API_TOKEN', False)
|
||||
v2_api_username = env.get('CLC_V2_API_USERNAME', False)
|
||||
v2_api_passwd = env.get('CLC_V2_API_PASSWD', False)
|
||||
clc_alias = env.get('CLC_ACCT_ALIAS', False)
|
||||
api_url = env.get('CLC_V2_API_URL', False)
|
||||
|
||||
if api_url:
|
||||
self.clc.defaults.ENDPOINT_URL_V2 = api_url
|
||||
|
||||
if v2_api_token and clc_alias:
|
||||
self.clc._LOGIN_TOKEN_V2 = v2_api_token
|
||||
self.clc._V2_ENABLED = True
|
||||
self.clc.ALIAS = clc_alias
|
||||
elif v2_api_username and v2_api_passwd:
|
||||
self.clc.v2.SetCredentials(
|
||||
api_username=v2_api_username,
|
||||
api_passwd=v2_api_passwd)
|
||||
else:
|
||||
return self.module.fail_json(
|
||||
msg="You must set the CLC_V2_API_USERNAME and CLC_V2_API_PASSWD "
|
||||
"environment variables")
|
||||
|
||||
def _ensure_firewall_policy_is_present(
|
||||
self,
|
||||
source_account_alias,
|
||||
location,
|
||||
firewall_dict):
|
||||
"""
|
||||
Ensures that a given firewall policy is present
|
||||
:param source_account_alias: the source account alias for the firewall policy
|
||||
:param location: datacenter of the firewall policy
|
||||
:param firewall_dict: dictionary of request parameters for firewall policy
|
||||
:return: (changed, firewall_policy_id, firewall_policy)
|
||||
changed: flag for if a change occurred
|
||||
firewall_policy_id: the firewall policy id that was created/updated
|
||||
firewall_policy: The firewall_policy object
|
||||
"""
|
||||
firewall_policy = None
|
||||
firewall_policy_id = firewall_dict.get('firewall_policy_id')
|
||||
|
||||
if firewall_policy_id is None:
|
||||
if not self.module.check_mode:
|
||||
response = self._create_firewall_policy(
|
||||
source_account_alias,
|
||||
location,
|
||||
firewall_dict)
|
||||
firewall_policy_id = self._get_policy_id_from_response(
|
||||
response)
|
||||
changed = True
|
||||
else:
|
||||
firewall_policy = self._get_firewall_policy(
|
||||
source_account_alias, location, firewall_policy_id)
|
||||
if not firewall_policy:
|
||||
return self.module.fail_json(
|
||||
msg='Unable to find the firewall policy id : {0}'.format(
|
||||
firewall_policy_id))
|
||||
changed = self._compare_get_request_with_dict(
|
||||
firewall_policy,
|
||||
firewall_dict)
|
||||
if not self.module.check_mode and changed:
|
||||
self._update_firewall_policy(
|
||||
source_account_alias,
|
||||
location,
|
||||
firewall_policy_id,
|
||||
firewall_dict)
|
||||
if changed and firewall_policy_id:
|
||||
firewall_policy = self._wait_for_requests_to_complete(
|
||||
source_account_alias,
|
||||
location,
|
||||
firewall_policy_id)
|
||||
return changed, firewall_policy_id, firewall_policy
|
||||
|
||||
def _ensure_firewall_policy_is_absent(
|
||||
self,
|
||||
source_account_alias,
|
||||
location,
|
||||
firewall_dict):
|
||||
"""
|
||||
Ensures that a given firewall policy is removed if present
|
||||
:param source_account_alias: the source account alias for the firewall policy
|
||||
:param location: datacenter of the firewall policy
|
||||
:param firewall_dict: firewall policy to delete
|
||||
:return: (changed, firewall_policy_id, response)
|
||||
changed: flag for if a change occurred
|
||||
firewall_policy_id: the firewall policy id that was deleted
|
||||
response: response from CLC API call
|
||||
"""
|
||||
changed = False
|
||||
response = []
|
||||
firewall_policy_id = firewall_dict.get('firewall_policy_id')
|
||||
result = self._get_firewall_policy(
|
||||
source_account_alias, location, firewall_policy_id)
|
||||
if result:
|
||||
if not self.module.check_mode:
|
||||
response = self._delete_firewall_policy(
|
||||
source_account_alias,
|
||||
location,
|
||||
firewall_policy_id)
|
||||
changed = True
|
||||
return changed, firewall_policy_id, response
|
||||
|
||||
def _create_firewall_policy(
|
||||
self,
|
||||
source_account_alias,
|
||||
location,
|
||||
firewall_dict):
|
||||
"""
|
||||
Creates the firewall policy for the given account alias
|
||||
:param source_account_alias: the source account alias for the firewall policy
|
||||
:param location: datacenter of the firewall policy
|
||||
:param firewall_dict: dictionary of request parameters for firewall policy
|
||||
:return: response from CLC API call
|
||||
"""
|
||||
payload = {
|
||||
'destinationAccount': firewall_dict.get('destination_account_alias'),
|
||||
'source': firewall_dict.get('source'),
|
||||
'destination': firewall_dict.get('destination'),
|
||||
'ports': firewall_dict.get('ports')}
|
||||
try:
|
||||
response = self.clc.v2.API.Call(
|
||||
'POST', '/v2-experimental/firewallPolicies/%s/%s' %
|
||||
(source_account_alias, location), payload)
|
||||
except APIFailedResponse as e:
|
||||
return self.module.fail_json(
|
||||
msg="Unable to create firewall policy. %s" %
|
||||
str(e.response_text))
|
||||
return response
|
||||
|
||||
def _delete_firewall_policy(
|
||||
self,
|
||||
source_account_alias,
|
||||
location,
|
||||
firewall_policy_id):
|
||||
"""
|
||||
Deletes a given firewall policy for an account alias in a datacenter
|
||||
:param source_account_alias: the source account alias for the firewall policy
|
||||
:param location: datacenter of the firewall policy
|
||||
:param firewall_policy_id: firewall policy id to delete
|
||||
:return: response: response from CLC API call
|
||||
"""
|
||||
try:
|
||||
response = self.clc.v2.API.Call(
|
||||
'DELETE', '/v2-experimental/firewallPolicies/%s/%s/%s' %
|
||||
(source_account_alias, location, firewall_policy_id))
|
||||
except APIFailedResponse as e:
|
||||
return self.module.fail_json(
|
||||
msg="Unable to delete the firewall policy id : {0}. {1}".format(
|
||||
firewall_policy_id, str(e.response_text)))
|
||||
return response
|
||||
|
||||
def _update_firewall_policy(
|
||||
self,
|
||||
source_account_alias,
|
||||
location,
|
||||
firewall_policy_id,
|
||||
firewall_dict):
|
||||
"""
|
||||
Updates a firewall policy for a given datacenter and account alias
|
||||
:param source_account_alias: the source account alias for the firewall policy
|
||||
:param location: datacenter of the firewall policy
|
||||
:param firewall_policy_id: firewall policy id to update
|
||||
:param firewall_dict: dictionary of request parameters for firewall policy
|
||||
:return: response: response from CLC API call
|
||||
"""
|
||||
try:
|
||||
response = self.clc.v2.API.Call(
|
||||
'PUT',
|
||||
'/v2-experimental/firewallPolicies/%s/%s/%s' %
|
||||
(source_account_alias,
|
||||
location,
|
||||
firewall_policy_id),
|
||||
firewall_dict)
|
||||
except APIFailedResponse as e:
|
||||
return self.module.fail_json(
|
||||
msg="Unable to update the firewall policy id : {0}. {1}".format(
|
||||
firewall_policy_id, str(e.response_text)))
|
||||
return response
|
||||
|
||||
@staticmethod
|
||||
def _compare_get_request_with_dict(response, firewall_dict):
|
||||
"""
|
||||
Helper method to compare the json response for getting the firewall policy with the request parameters
|
||||
:param response: response from the get method
|
||||
:param firewall_dict: dictionary of request parameters for firewall policy
|
||||
:return: changed: Boolean that returns true if there are differences between
|
||||
the response parameters and the playbook parameters
|
||||
"""
|
||||
|
||||
changed = False
|
||||
|
||||
response_dest_account_alias = response.get('destinationAccount')
|
||||
response_enabled = response.get('enabled')
|
||||
response_source = response.get('source')
|
||||
response_dest = response.get('destination')
|
||||
response_ports = response.get('ports')
|
||||
request_dest_account_alias = firewall_dict.get(
|
||||
'destination_account_alias')
|
||||
request_enabled = firewall_dict.get('enabled')
|
||||
if request_enabled is None:
|
||||
request_enabled = True
|
||||
request_source = firewall_dict.get('source')
|
||||
request_dest = firewall_dict.get('destination')
|
||||
request_ports = firewall_dict.get('ports')
|
||||
|
||||
if (
|
||||
response_dest_account_alias and str(response_dest_account_alias) != str(request_dest_account_alias)) or (
|
||||
response_enabled != request_enabled) or (
|
||||
response_source and response_source != request_source) or (
|
||||
response_dest and response_dest != request_dest) or (
|
||||
response_ports and response_ports != request_ports):
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
def _get_firewall_policy(
|
||||
self,
|
||||
source_account_alias,
|
||||
location,
|
||||
firewall_policy_id):
|
||||
"""
|
||||
Get back details for a particular firewall policy
|
||||
:param source_account_alias: the source account alias for the firewall policy
|
||||
:param location: datacenter of the firewall policy
|
||||
:param firewall_policy_id: id of the firewall policy to get
|
||||
:return: response - The response from CLC API call
|
||||
"""
|
||||
response = None
|
||||
try:
|
||||
response = self.clc.v2.API.Call(
|
||||
'GET', '/v2-experimental/firewallPolicies/%s/%s/%s' %
|
||||
(source_account_alias, location, firewall_policy_id))
|
||||
except APIFailedResponse as e:
|
||||
if e.response_status_code != 404:
|
||||
self.module.fail_json(
|
||||
msg="Unable to fetch the firewall policy with id : {0}. {1}".format(
|
||||
firewall_policy_id, str(e.response_text)))
|
||||
return response
|
||||
|
||||
def _wait_for_requests_to_complete(
|
||||
self,
|
||||
source_account_alias,
|
||||
location,
|
||||
firewall_policy_id,
|
||||
wait_limit=50):
|
||||
"""
|
||||
Waits until the CLC requests are complete if the wait argument is True
|
||||
:param source_account_alias: The source account alias for the firewall policy
|
||||
:param location: datacenter of the firewall policy
|
||||
:param firewall_policy_id: The firewall policy id
|
||||
:param wait_limit: The number of times to check the status for completion
|
||||
:return: the firewall_policy object
|
||||
"""
|
||||
wait = self.module.params.get('wait')
|
||||
count = 0
|
||||
firewall_policy = None
|
||||
while wait:
|
||||
count += 1
|
||||
firewall_policy = self._get_firewall_policy(
|
||||
source_account_alias, location, firewall_policy_id)
|
||||
status = firewall_policy.get('status')
|
||||
if status == 'active' or count > wait_limit:
|
||||
wait = False
|
||||
else:
|
||||
# wait for 2 seconds
|
||||
sleep(2)
|
||||
return firewall_policy
|
||||
|
||||
@staticmethod
|
||||
def _set_user_agent(clc):
|
||||
if hasattr(clc, 'SetRequestsSession'):
|
||||
agent_string = "ClcAnsibleModule/" + __version__
|
||||
ses = requests.Session()
|
||||
ses.headers.update({"Api-Client": agent_string})
|
||||
ses.headers['User-Agent'] += " " + agent_string
|
||||
clc.SetRequestsSession(ses)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
The main function. Instantiates the module and calls process_request.
|
||||
:return: none
|
||||
"""
|
||||
module = AnsibleModule(
|
||||
argument_spec=ClcFirewallPolicy._define_module_argument_spec(),
|
||||
supports_check_mode=True)
|
||||
|
||||
clc_firewall = ClcFirewallPolicy(module)
|
||||
clc_firewall.process_request()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
512
plugins/modules/clc_group.py
Normal file
512
plugins/modules/clc_group.py
Normal file
@@ -0,0 +1,512 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2015 CenturyLink
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: clc_group
|
||||
short_description: Create/delete Server Groups at Centurylink Cloud
|
||||
description:
|
||||
- Create or delete Server Groups at Centurylink Centurylink Cloud.
|
||||
deprecated:
|
||||
removed_in: 11.0.0
|
||||
why: >
|
||||
Lumen Public Cloud (formerly known as CenturyLink Cloud) has gone End-of-Life in September 2023.
|
||||
See more at U(https://www.ctl.io/knowledge-base/release-notes/2023/lumen-public-cloud-platform-end-of-life-notice/?).
|
||||
alternative: There is none.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
- community.general.clc
|
||||
author:
|
||||
- "CLC Runner (@clc-runner)"
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
options:
|
||||
name:
|
||||
description:
|
||||
- The name of the Server Group.
|
||||
type: str
|
||||
required: true
|
||||
description:
|
||||
description:
|
||||
- A description of the Server Group.
|
||||
type: str
|
||||
required: false
|
||||
parent:
|
||||
description:
|
||||
- The parent group of the server group. If parent is not provided, it creates the group at top level.
|
||||
type: str
|
||||
required: false
|
||||
location:
|
||||
description:
|
||||
- Datacenter to create the group in. If location is not provided, the group gets created in the default datacenter associated
|
||||
with the account.
|
||||
type: str
|
||||
required: false
|
||||
state:
|
||||
description:
|
||||
- Whether to create or delete the group.
|
||||
type: str
|
||||
default: present
|
||||
choices: ['present', 'absent']
|
||||
wait:
|
||||
description:
|
||||
- Whether to wait for the tasks to finish before returning.
|
||||
type: bool
|
||||
default: true
|
||||
required: false
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
# Create a Server Group
|
||||
- name: Create Server Group
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Create / Verify a Server Group at CenturyLink Cloud
|
||||
community.general.clc_group:
|
||||
name: My Cool Server Group
|
||||
parent: Default Group
|
||||
state: present
|
||||
register: clc
|
||||
|
||||
- name: Debug
|
||||
ansible.builtin.debug:
|
||||
var: clc
|
||||
|
||||
# Delete a Server Group
|
||||
- name: Delete Server Group
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Delete / Verify Absent a Server Group at CenturyLink Cloud
|
||||
community.general.clc_group:
|
||||
name: My Cool Server Group
|
||||
parent: Default Group
|
||||
state: absent
|
||||
register: clc
|
||||
|
||||
- name: Debug
|
||||
ansible.builtin.debug:
|
||||
var: clc
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
group:
|
||||
description: The group information.
|
||||
returned: success
|
||||
type: dict
|
||||
sample:
|
||||
{
|
||||
"changeInfo":{
|
||||
"createdBy":"service.wfad",
|
||||
"createdDate":"2015-07-29T18:52:47Z",
|
||||
"modifiedBy":"service.wfad",
|
||||
"modifiedDate":"2015-07-29T18:52:47Z"
|
||||
},
|
||||
"customFields":[
|
||||
|
||||
],
|
||||
"description":"test group",
|
||||
"groups":[
|
||||
|
||||
],
|
||||
"id":"bb5f12a3c6044ae4ad0a03e73ae12cd1",
|
||||
"links":[
|
||||
{
|
||||
"href":"/v2/groups/wfad",
|
||||
"rel":"createGroup",
|
||||
"verbs":[
|
||||
"POST"
|
||||
]
|
||||
},
|
||||
{
|
||||
"href":"/v2/servers/wfad",
|
||||
"rel":"createServer",
|
||||
"verbs":[
|
||||
"POST"
|
||||
]
|
||||
},
|
||||
{
|
||||
"href":"/v2/groups/wfad/bb5f12a3c6044ae4ad0a03e73ae12cd1",
|
||||
"rel":"self",
|
||||
"verbs":[
|
||||
"GET",
|
||||
"PATCH",
|
||||
"DELETE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"href":"/v2/groups/wfad/086ac1dfe0b6411989e8d1b77c4065f0",
|
||||
"id":"086ac1dfe0b6411989e8d1b77c4065f0",
|
||||
"rel":"parentGroup"
|
||||
},
|
||||
{
|
||||
"href":"/v2/groups/wfad/bb5f12a3c6044ae4ad0a03e73ae12cd1/defaults",
|
||||
"rel":"defaults",
|
||||
"verbs":[
|
||||
"GET",
|
||||
"POST"
|
||||
]
|
||||
},
|
||||
{
|
||||
"href":"/v2/groups/wfad/bb5f12a3c6044ae4ad0a03e73ae12cd1/billing",
|
||||
"rel":"billing"
|
||||
},
|
||||
{
|
||||
"href":"/v2/groups/wfad/bb5f12a3c6044ae4ad0a03e73ae12cd1/archive",
|
||||
"rel":"archiveGroupAction"
|
||||
},
|
||||
{
|
||||
"href":"/v2/groups/wfad/bb5f12a3c6044ae4ad0a03e73ae12cd1/statistics",
|
||||
"rel":"statistics"
|
||||
},
|
||||
{
|
||||
"href":"/v2/groups/wfad/bb5f12a3c6044ae4ad0a03e73ae12cd1/upcomingScheduledActivities",
|
||||
"rel":"upcomingScheduledActivities"
|
||||
},
|
||||
{
|
||||
"href":"/v2/groups/wfad/bb5f12a3c6044ae4ad0a03e73ae12cd1/horizontalAutoscalePolicy",
|
||||
"rel":"horizontalAutoscalePolicyMapping",
|
||||
"verbs":[
|
||||
"GET",
|
||||
"PUT",
|
||||
"DELETE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"href":"/v2/groups/wfad/bb5f12a3c6044ae4ad0a03e73ae12cd1/scheduledActivities",
|
||||
"rel":"scheduledActivities",
|
||||
"verbs":[
|
||||
"GET",
|
||||
"POST"
|
||||
]
|
||||
}
|
||||
],
|
||||
"locationId":"UC1",
|
||||
"name":"test group",
|
||||
"status":"active",
|
||||
"type":"default"
|
||||
}
|
||||
"""
|
||||
|
||||
__version__ = '${version}'
|
||||
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
REQUESTS_IMP_ERR = None
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
REQUESTS_IMP_ERR = traceback.format_exc()
|
||||
REQUESTS_FOUND = False
|
||||
else:
|
||||
REQUESTS_FOUND = True
|
||||
|
||||
#
|
||||
# Requires the clc-python-sdk.
|
||||
# sudo pip install clc-sdk
|
||||
#
|
||||
CLC_IMP_ERR = None
|
||||
try:
|
||||
import clc as clc_sdk
|
||||
from clc import CLCException
|
||||
except ImportError:
|
||||
CLC_IMP_ERR = traceback.format_exc()
|
||||
CLC_FOUND = False
|
||||
clc_sdk = None
|
||||
else:
|
||||
CLC_FOUND = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
|
||||
class ClcGroup(object):
|
||||
|
||||
clc = None
|
||||
root_group = None
|
||||
|
||||
def __init__(self, module):
|
||||
"""
|
||||
Construct module
|
||||
"""
|
||||
self.clc = clc_sdk
|
||||
self.module = module
|
||||
self.group_dict = {}
|
||||
|
||||
if not CLC_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR)
|
||||
if not REQUESTS_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR)
|
||||
if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'):
|
||||
self.module.fail_json(
|
||||
msg='requests library version should be >= 2.5.0')
|
||||
|
||||
self._set_user_agent(self.clc)
|
||||
|
||||
def process_request(self):
|
||||
"""
|
||||
Execute the main code path, and handle the request
|
||||
:return: none
|
||||
"""
|
||||
location = self.module.params.get('location')
|
||||
group_name = self.module.params.get('name')
|
||||
parent_name = self.module.params.get('parent')
|
||||
group_description = self.module.params.get('description')
|
||||
state = self.module.params.get('state')
|
||||
|
||||
self._set_clc_credentials_from_env()
|
||||
self.group_dict = self._get_group_tree_for_datacenter(
|
||||
datacenter=location)
|
||||
|
||||
if state == "absent":
|
||||
changed, group, requests = self._ensure_group_is_absent(
|
||||
group_name=group_name, parent_name=parent_name)
|
||||
if requests:
|
||||
self._wait_for_requests_to_complete(requests)
|
||||
else:
|
||||
changed, group = self._ensure_group_is_present(
|
||||
group_name=group_name, parent_name=parent_name, group_description=group_description)
|
||||
try:
|
||||
group = group.data
|
||||
except AttributeError:
|
||||
group = group_name
|
||||
self.module.exit_json(changed=changed, group=group)
|
||||
|
||||
@staticmethod
|
||||
def _define_module_argument_spec():
|
||||
"""
|
||||
Define the argument spec for the ansible module
|
||||
:return: argument spec dictionary
|
||||
"""
|
||||
argument_spec = dict(
|
||||
name=dict(required=True),
|
||||
description=dict(),
|
||||
parent=dict(),
|
||||
location=dict(),
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
wait=dict(type='bool', default=True))
|
||||
|
||||
return argument_spec
|
||||
|
||||
def _set_clc_credentials_from_env(self):
|
||||
"""
|
||||
Set the CLC Credentials on the sdk by reading environment variables
|
||||
:return: none
|
||||
"""
|
||||
env = os.environ
|
||||
v2_api_token = env.get('CLC_V2_API_TOKEN', False)
|
||||
v2_api_username = env.get('CLC_V2_API_USERNAME', False)
|
||||
v2_api_passwd = env.get('CLC_V2_API_PASSWD', False)
|
||||
clc_alias = env.get('CLC_ACCT_ALIAS', False)
|
||||
api_url = env.get('CLC_V2_API_URL', False)
|
||||
|
||||
if api_url:
|
||||
self.clc.defaults.ENDPOINT_URL_V2 = api_url
|
||||
|
||||
if v2_api_token and clc_alias:
|
||||
self.clc._LOGIN_TOKEN_V2 = v2_api_token
|
||||
self.clc._V2_ENABLED = True
|
||||
self.clc.ALIAS = clc_alias
|
||||
elif v2_api_username and v2_api_passwd:
|
||||
self.clc.v2.SetCredentials(
|
||||
api_username=v2_api_username,
|
||||
api_passwd=v2_api_passwd)
|
||||
else:
|
||||
return self.module.fail_json(
|
||||
msg="You must set the CLC_V2_API_USERNAME and CLC_V2_API_PASSWD "
|
||||
"environment variables")
|
||||
|
||||
def _ensure_group_is_absent(self, group_name, parent_name):
|
||||
"""
|
||||
Ensure that group_name is absent by deleting it if necessary
|
||||
:param group_name: string - the name of the clc server group to delete
|
||||
:param parent_name: string - the name of the parent group for group_name
|
||||
:return: changed, group
|
||||
"""
|
||||
changed = False
|
||||
group = []
|
||||
results = []
|
||||
|
||||
if self._group_exists(group_name=group_name, parent_name=parent_name):
|
||||
if not self.module.check_mode:
|
||||
group.append(group_name)
|
||||
result = self._delete_group(group_name)
|
||||
results.append(result)
|
||||
changed = True
|
||||
return changed, group, results
|
||||
|
||||
def _delete_group(self, group_name):
|
||||
"""
|
||||
Delete the provided server group
|
||||
:param group_name: string - the server group to delete
|
||||
:return: none
|
||||
"""
|
||||
response = None
|
||||
group, parent = self.group_dict.get(group_name)
|
||||
try:
|
||||
response = group.Delete()
|
||||
except CLCException as ex:
|
||||
self.module.fail_json(msg='Failed to delete group :{0}. {1}'.format(
|
||||
group_name, ex.response_text
|
||||
))
|
||||
return response
|
||||
|
||||
def _ensure_group_is_present(
|
||||
self,
|
||||
group_name,
|
||||
parent_name,
|
||||
group_description):
|
||||
"""
|
||||
Checks to see if a server group exists, creates it if it doesn't.
|
||||
:param group_name: the name of the group to validate/create
|
||||
:param parent_name: the name of the parent group for group_name
|
||||
:param group_description: a short description of the server group (used when creating)
|
||||
:return: (changed, group) -
|
||||
changed: Boolean- whether a change was made,
|
||||
group: A clc group object for the group
|
||||
"""
|
||||
if not self.root_group:
|
||||
raise AssertionError("Implementation Error: Root Group not set")
|
||||
parent = parent_name if parent_name is not None else self.root_group.name
|
||||
description = group_description
|
||||
changed = False
|
||||
group = group_name
|
||||
|
||||
parent_exists = self._group_exists(group_name=parent, parent_name=None)
|
||||
child_exists = self._group_exists(
|
||||
group_name=group_name,
|
||||
parent_name=parent)
|
||||
|
||||
if parent_exists and child_exists:
|
||||
group, parent = self.group_dict[group_name]
|
||||
changed = False
|
||||
elif parent_exists and not child_exists:
|
||||
if not self.module.check_mode:
|
||||
group = self._create_group(
|
||||
group=group,
|
||||
parent=parent,
|
||||
description=description)
|
||||
changed = True
|
||||
else:
|
||||
self.module.fail_json(
|
||||
msg="parent group: " +
|
||||
parent +
|
||||
" does not exist")
|
||||
|
||||
return changed, group
|
||||
|
||||
def _create_group(self, group, parent, description):
|
||||
"""
|
||||
Create the provided server group
|
||||
:param group: clc_sdk.Group - the group to create
|
||||
:param parent: clc_sdk.Parent - the parent group for {group}
|
||||
:param description: string - a text description of the group
|
||||
:return: clc_sdk.Group - the created group
|
||||
"""
|
||||
response = None
|
||||
(parent, grandparent) = self.group_dict[parent]
|
||||
try:
|
||||
response = parent.Create(name=group, description=description)
|
||||
except CLCException as ex:
|
||||
self.module.fail_json(msg='Failed to create group :{0}. {1}'.format(
|
||||
group, ex.response_text))
|
||||
return response
|
||||
|
||||
def _group_exists(self, group_name, parent_name):
|
||||
"""
|
||||
Check to see if a group exists
|
||||
:param group_name: string - the group to check
|
||||
:param parent_name: string - the parent of group_name
|
||||
:return: boolean - whether the group exists
|
||||
"""
|
||||
result = False
|
||||
if group_name in self.group_dict:
|
||||
(group, parent) = self.group_dict[group_name]
|
||||
if parent_name is None or parent_name == parent.name:
|
||||
result = True
|
||||
return result
|
||||
|
||||
def _get_group_tree_for_datacenter(self, datacenter=None):
|
||||
"""
|
||||
Walk the tree of groups for a datacenter
|
||||
:param datacenter: string - the datacenter to walk (ex: 'UC1')
|
||||
:return: a dictionary of groups and parents
|
||||
"""
|
||||
self.root_group = self.clc.v2.Datacenter(
|
||||
location=datacenter).RootGroup()
|
||||
return self._walk_groups_recursive(
|
||||
parent_group=None,
|
||||
child_group=self.root_group)
|
||||
|
||||
def _walk_groups_recursive(self, parent_group, child_group):
|
||||
"""
|
||||
Walk a parent-child tree of groups, starting with the provided child group
|
||||
:param parent_group: clc_sdk.Group - the parent group to start the walk
|
||||
:param child_group: clc_sdk.Group - the child group to start the walk
|
||||
:return: a dictionary of groups and parents
|
||||
"""
|
||||
result = {str(child_group): (child_group, parent_group)}
|
||||
groups = child_group.Subgroups().groups
|
||||
if len(groups) > 0:
|
||||
for group in groups:
|
||||
if group.type != 'default':
|
||||
continue
|
||||
|
||||
result.update(self._walk_groups_recursive(child_group, group))
|
||||
return result
|
||||
|
||||
def _wait_for_requests_to_complete(self, requests_lst):
|
||||
"""
|
||||
Waits until the CLC requests are complete if the wait argument is True
|
||||
:param requests_lst: The list of CLC request objects
|
||||
:return: none
|
||||
"""
|
||||
if not self.module.params['wait']:
|
||||
return
|
||||
for request in requests_lst:
|
||||
request.WaitUntilComplete()
|
||||
for request_details in request.requests:
|
||||
if request_details.Status() != 'succeeded':
|
||||
self.module.fail_json(
|
||||
msg='Unable to process group request')
|
||||
|
||||
@staticmethod
|
||||
def _set_user_agent(clc):
|
||||
if hasattr(clc, 'SetRequestsSession'):
|
||||
agent_string = "ClcAnsibleModule/" + __version__
|
||||
ses = requests.Session()
|
||||
ses.headers.update({"Api-Client": agent_string})
|
||||
ses.headers['User-Agent'] += " " + agent_string
|
||||
clc.SetRequestsSession(ses)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
The main function. Instantiates the module and calls process_request.
|
||||
:return: none
|
||||
"""
|
||||
module = AnsibleModule(
|
||||
argument_spec=ClcGroup._define_module_argument_spec(),
|
||||
supports_check_mode=True)
|
||||
|
||||
clc_group = ClcGroup(module)
|
||||
clc_group.process_request()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
938
plugins/modules/clc_loadbalancer.py
Normal file
938
plugins/modules/clc_loadbalancer.py
Normal file
@@ -0,0 +1,938 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2015 CenturyLink
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: clc_loadbalancer
|
||||
short_description: Create, Delete shared loadbalancers in CenturyLink Cloud
|
||||
description:
|
||||
- An Ansible module to Create, Delete shared loadbalancers in CenturyLink Cloud.
|
||||
deprecated:
|
||||
removed_in: 11.0.0
|
||||
why: >
|
||||
Lumen Public Cloud (formerly known as CenturyLink Cloud) has gone End-of-Life in September 2023.
|
||||
See more at U(https://www.ctl.io/knowledge-base/release-notes/2023/lumen-public-cloud-platform-end-of-life-notice/?).
|
||||
alternative: There is none.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
- community.general.clc
|
||||
author:
|
||||
- "CLC Runner (@clc-runner)"
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
options:
|
||||
name:
|
||||
description:
|
||||
- The name of the loadbalancer.
|
||||
type: str
|
||||
required: true
|
||||
description:
|
||||
description:
|
||||
- A description for the loadbalancer.
|
||||
type: str
|
||||
alias:
|
||||
description:
|
||||
- The alias of your CLC Account.
|
||||
type: str
|
||||
required: true
|
||||
location:
|
||||
description:
|
||||
- The location of the datacenter where the load balancer resides in.
|
||||
type: str
|
||||
required: true
|
||||
method:
|
||||
description:
|
||||
- The balancing method for the load balancer pool.
|
||||
type: str
|
||||
choices: ['leastConnection', 'roundRobin']
|
||||
persistence:
|
||||
description:
|
||||
- The persistence method for the load balancer.
|
||||
type: str
|
||||
choices: ['standard', 'sticky']
|
||||
port:
|
||||
description:
|
||||
- Port to configure on the public-facing side of the load balancer pool.
|
||||
type: str
|
||||
choices: ['80', '443']
|
||||
nodes:
|
||||
description:
|
||||
- A list of nodes that needs to be added to the load balancer pool.
|
||||
type: list
|
||||
default: []
|
||||
elements: dict
|
||||
status:
|
||||
description:
|
||||
- The status of the loadbalancer.
|
||||
type: str
|
||||
default: enabled
|
||||
choices: ['enabled', 'disabled']
|
||||
state:
|
||||
description:
|
||||
- Whether to create or delete the load balancer pool.
|
||||
type: str
|
||||
default: present
|
||||
choices: ['present', 'absent', 'port_absent', 'nodes_present', 'nodes_absent']
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
# Note - You must set the CLC_V2_API_USERNAME And CLC_V2_API_PASSWD Environment variables before running these examples
|
||||
- name: Create Loadbalancer
|
||||
hosts: localhost
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Actually Create things
|
||||
community.general.clc_loadbalancer:
|
||||
name: test
|
||||
description: test
|
||||
alias: TEST
|
||||
location: WA1
|
||||
port: 443
|
||||
nodes:
|
||||
- ipAddress: 10.11.22.123
|
||||
privatePort: 80
|
||||
state: present
|
||||
|
||||
- name: Add node to an existing loadbalancer pool
|
||||
hosts: localhost
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Actually Create things
|
||||
community.general.clc_loadbalancer:
|
||||
name: test
|
||||
description: test
|
||||
alias: TEST
|
||||
location: WA1
|
||||
port: 443
|
||||
nodes:
|
||||
- ipAddress: 10.11.22.234
|
||||
privatePort: 80
|
||||
state: nodes_present
|
||||
|
||||
- name: Remove node from an existing loadbalancer pool
|
||||
hosts: localhost
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Actually Create things
|
||||
community.general.clc_loadbalancer:
|
||||
name: test
|
||||
description: test
|
||||
alias: TEST
|
||||
location: WA1
|
||||
port: 443
|
||||
nodes:
|
||||
- ipAddress: 10.11.22.234
|
||||
privatePort: 80
|
||||
state: nodes_absent
|
||||
|
||||
- name: Delete LoadbalancerPool
|
||||
hosts: localhost
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Actually Delete things
|
||||
community.general.clc_loadbalancer:
|
||||
name: test
|
||||
description: test
|
||||
alias: TEST
|
||||
location: WA1
|
||||
port: 443
|
||||
nodes:
|
||||
- ipAddress: 10.11.22.123
|
||||
privatePort: 80
|
||||
state: port_absent
|
||||
|
||||
- name: Delete Loadbalancer
|
||||
hosts: localhost
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Actually Delete things
|
||||
community.general.clc_loadbalancer:
|
||||
name: test
|
||||
description: test
|
||||
alias: TEST
|
||||
location: WA1
|
||||
port: 443
|
||||
nodes:
|
||||
- ipAddress: 10.11.22.123
|
||||
privatePort: 80
|
||||
state: absent
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
loadbalancer:
|
||||
description: The load balancer result object from CLC.
|
||||
returned: success
|
||||
type: dict
|
||||
sample:
|
||||
{
|
||||
"description":"test-lb",
|
||||
"id":"ab5b18cb81e94ab9925b61d1ca043fb5",
|
||||
"ipAddress":"66.150.174.197",
|
||||
"links":[
|
||||
{
|
||||
"href":"/v2/sharedLoadBalancers/wfad/wa1/ab5b18cb81e94ab9925b61d1ca043fb5",
|
||||
"rel":"self",
|
||||
"verbs":[
|
||||
"GET",
|
||||
"PUT",
|
||||
"DELETE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"href":"/v2/sharedLoadBalancers/wfad/wa1/ab5b18cb81e94ab9925b61d1ca043fb5/pools",
|
||||
"rel":"pools",
|
||||
"verbs":[
|
||||
"GET",
|
||||
"POST"
|
||||
]
|
||||
}
|
||||
],
|
||||
"name":"test-lb",
|
||||
"pools":[
|
||||
|
||||
],
|
||||
"status":"enabled"
|
||||
}
|
||||
"""
|
||||
|
||||
__version__ = '${version}'
|
||||
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
from time import sleep
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
REQUESTS_IMP_ERR = None
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
REQUESTS_IMP_ERR = traceback.format_exc()
|
||||
REQUESTS_FOUND = False
|
||||
else:
|
||||
REQUESTS_FOUND = True
|
||||
|
||||
#
|
||||
# Requires the clc-python-sdk.
|
||||
# sudo pip install clc-sdk
|
||||
#
|
||||
CLC_IMP_ERR = None
|
||||
try:
|
||||
import clc as clc_sdk
|
||||
from clc import APIFailedResponse
|
||||
except ImportError:
|
||||
CLC_IMP_ERR = traceback.format_exc()
|
||||
CLC_FOUND = False
|
||||
clc_sdk = None
|
||||
else:
|
||||
CLC_FOUND = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
|
||||
class ClcLoadBalancer:
|
||||
|
||||
clc = None
|
||||
|
||||
def __init__(self, module):
|
||||
"""
|
||||
Construct module
|
||||
"""
|
||||
self.clc = clc_sdk
|
||||
self.module = module
|
||||
self.lb_dict = {}
|
||||
|
||||
if not CLC_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR)
|
||||
if not REQUESTS_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR)
|
||||
if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'):
|
||||
self.module.fail_json(
|
||||
msg='requests library version should be >= 2.5.0')
|
||||
|
||||
self._set_user_agent(self.clc)
|
||||
|
||||
def process_request(self):
|
||||
"""
|
||||
Execute the main code path, and handle the request
|
||||
:return: none
|
||||
"""
|
||||
changed = False
|
||||
result_lb = None
|
||||
loadbalancer_name = self.module.params.get('name')
|
||||
loadbalancer_alias = self.module.params.get('alias')
|
||||
loadbalancer_location = self.module.params.get('location')
|
||||
loadbalancer_description = self.module.params.get('description')
|
||||
loadbalancer_port = self.module.params.get('port')
|
||||
loadbalancer_method = self.module.params.get('method')
|
||||
loadbalancer_persistence = self.module.params.get('persistence')
|
||||
loadbalancer_nodes = self.module.params.get('nodes')
|
||||
loadbalancer_status = self.module.params.get('status')
|
||||
state = self.module.params.get('state')
|
||||
|
||||
if loadbalancer_description is None:
|
||||
loadbalancer_description = loadbalancer_name
|
||||
|
||||
self._set_clc_credentials_from_env()
|
||||
|
||||
self.lb_dict = self._get_loadbalancer_list(
|
||||
alias=loadbalancer_alias,
|
||||
location=loadbalancer_location)
|
||||
|
||||
if state == 'present':
|
||||
changed, result_lb, lb_id = self.ensure_loadbalancer_present(
|
||||
name=loadbalancer_name,
|
||||
alias=loadbalancer_alias,
|
||||
location=loadbalancer_location,
|
||||
description=loadbalancer_description,
|
||||
status=loadbalancer_status)
|
||||
if loadbalancer_port:
|
||||
changed, result_pool, pool_id = self.ensure_loadbalancerpool_present(
|
||||
lb_id=lb_id,
|
||||
alias=loadbalancer_alias,
|
||||
location=loadbalancer_location,
|
||||
method=loadbalancer_method,
|
||||
persistence=loadbalancer_persistence,
|
||||
port=loadbalancer_port)
|
||||
|
||||
if loadbalancer_nodes:
|
||||
changed, result_nodes = self.ensure_lbpool_nodes_set(
|
||||
alias=loadbalancer_alias,
|
||||
location=loadbalancer_location,
|
||||
name=loadbalancer_name,
|
||||
port=loadbalancer_port,
|
||||
nodes=loadbalancer_nodes)
|
||||
elif state == 'absent':
|
||||
changed, result_lb = self.ensure_loadbalancer_absent(
|
||||
name=loadbalancer_name,
|
||||
alias=loadbalancer_alias,
|
||||
location=loadbalancer_location)
|
||||
|
||||
elif state == 'port_absent':
|
||||
changed, result_lb = self.ensure_loadbalancerpool_absent(
|
||||
alias=loadbalancer_alias,
|
||||
location=loadbalancer_location,
|
||||
name=loadbalancer_name,
|
||||
port=loadbalancer_port)
|
||||
|
||||
elif state == 'nodes_present':
|
||||
changed, result_lb = self.ensure_lbpool_nodes_present(
|
||||
alias=loadbalancer_alias,
|
||||
location=loadbalancer_location,
|
||||
name=loadbalancer_name,
|
||||
port=loadbalancer_port,
|
||||
nodes=loadbalancer_nodes)
|
||||
|
||||
elif state == 'nodes_absent':
|
||||
changed, result_lb = self.ensure_lbpool_nodes_absent(
|
||||
alias=loadbalancer_alias,
|
||||
location=loadbalancer_location,
|
||||
name=loadbalancer_name,
|
||||
port=loadbalancer_port,
|
||||
nodes=loadbalancer_nodes)
|
||||
|
||||
self.module.exit_json(changed=changed, loadbalancer=result_lb)
|
||||
|
||||
def ensure_loadbalancer_present(
|
||||
self, name, alias, location, description, status):
|
||||
"""
|
||||
Checks to see if a load balancer exists and creates one if it does not.
|
||||
:param name: Name of loadbalancer
|
||||
:param alias: Alias of account
|
||||
:param location: Datacenter
|
||||
:param description: Description of loadbalancer
|
||||
:param status: Enabled / Disabled
|
||||
:return: (changed, result, lb_id)
|
||||
changed: Boolean whether a change was made
|
||||
result: The result object from the CLC load balancer request
|
||||
lb_id: The load balancer id
|
||||
"""
|
||||
changed = False
|
||||
result = name
|
||||
lb_id = self._loadbalancer_exists(name=name)
|
||||
if not lb_id:
|
||||
if not self.module.check_mode:
|
||||
result = self.create_loadbalancer(name=name,
|
||||
alias=alias,
|
||||
location=location,
|
||||
description=description,
|
||||
status=status)
|
||||
lb_id = result.get('id')
|
||||
changed = True
|
||||
|
||||
return changed, result, lb_id
|
||||
|
||||
def ensure_loadbalancerpool_present(
|
||||
self, lb_id, alias, location, method, persistence, port):
|
||||
"""
|
||||
Checks to see if a load balancer pool exists and creates one if it does not.
|
||||
:param lb_id: The loadbalancer id
|
||||
:param alias: The account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param method: the load balancing method
|
||||
:param persistence: the load balancing persistence type
|
||||
:param port: the port that the load balancer will listen on
|
||||
:return: (changed, group, pool_id) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
pool_id: The string id of the load balancer pool
|
||||
"""
|
||||
changed = False
|
||||
result = port
|
||||
if not lb_id:
|
||||
return changed, None, None
|
||||
pool_id = self._loadbalancerpool_exists(
|
||||
alias=alias,
|
||||
location=location,
|
||||
port=port,
|
||||
lb_id=lb_id)
|
||||
if not pool_id:
|
||||
if not self.module.check_mode:
|
||||
result = self.create_loadbalancerpool(
|
||||
alias=alias,
|
||||
location=location,
|
||||
lb_id=lb_id,
|
||||
method=method,
|
||||
persistence=persistence,
|
||||
port=port)
|
||||
pool_id = result.get('id')
|
||||
changed = True
|
||||
|
||||
return changed, result, pool_id
|
||||
|
||||
def ensure_loadbalancer_absent(self, name, alias, location):
|
||||
"""
|
||||
Checks to see if a load balancer exists and deletes it if it does
|
||||
:param name: Name of the load balancer
|
||||
:param alias: Alias of account
|
||||
:param location: Datacenter
|
||||
:return: (changed, result)
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API Call
|
||||
"""
|
||||
changed = False
|
||||
result = name
|
||||
lb_exists = self._loadbalancer_exists(name=name)
|
||||
if lb_exists:
|
||||
if not self.module.check_mode:
|
||||
result = self.delete_loadbalancer(alias=alias,
|
||||
location=location,
|
||||
name=name)
|
||||
changed = True
|
||||
return changed, result
|
||||
|
||||
def ensure_loadbalancerpool_absent(self, alias, location, name, port):
|
||||
"""
|
||||
Checks to see if a load balancer pool exists and deletes it if it does
|
||||
:param alias: The account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param name: the name of the load balancer
|
||||
:param port: the port that the load balancer listens on
|
||||
:return: (changed, result) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
"""
|
||||
changed = False
|
||||
result = None
|
||||
lb_exists = self._loadbalancer_exists(name=name)
|
||||
if lb_exists:
|
||||
lb_id = self._get_loadbalancer_id(name=name)
|
||||
pool_id = self._loadbalancerpool_exists(
|
||||
alias=alias,
|
||||
location=location,
|
||||
port=port,
|
||||
lb_id=lb_id)
|
||||
if pool_id:
|
||||
changed = True
|
||||
if not self.module.check_mode:
|
||||
result = self.delete_loadbalancerpool(
|
||||
alias=alias,
|
||||
location=location,
|
||||
lb_id=lb_id,
|
||||
pool_id=pool_id)
|
||||
else:
|
||||
result = "Pool doesn't exist"
|
||||
else:
|
||||
result = "LB Doesn't Exist"
|
||||
return changed, result
|
||||
|
||||
def ensure_lbpool_nodes_set(self, alias, location, name, port, nodes):
|
||||
"""
|
||||
Checks to see if the provided list of nodes exist for the pool
|
||||
and set the nodes if any in the list those doesn't exist
|
||||
:param alias: The account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param name: the name of the load balancer
|
||||
:param port: the port that the load balancer will listen on
|
||||
:param nodes: The list of nodes to be updated to the pool
|
||||
:return: (changed, result) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
"""
|
||||
result = {}
|
||||
changed = False
|
||||
lb_exists = self._loadbalancer_exists(name=name)
|
||||
if lb_exists:
|
||||
lb_id = self._get_loadbalancer_id(name=name)
|
||||
pool_id = self._loadbalancerpool_exists(
|
||||
alias=alias,
|
||||
location=location,
|
||||
port=port,
|
||||
lb_id=lb_id)
|
||||
if pool_id:
|
||||
nodes_exist = self._loadbalancerpool_nodes_exists(alias=alias,
|
||||
location=location,
|
||||
lb_id=lb_id,
|
||||
pool_id=pool_id,
|
||||
nodes_to_check=nodes)
|
||||
if not nodes_exist:
|
||||
changed = True
|
||||
result = self.set_loadbalancernodes(alias=alias,
|
||||
location=location,
|
||||
lb_id=lb_id,
|
||||
pool_id=pool_id,
|
||||
nodes=nodes)
|
||||
else:
|
||||
result = "Pool doesn't exist"
|
||||
else:
|
||||
result = "Load balancer doesn't Exist"
|
||||
return changed, result
|
||||
|
||||
def ensure_lbpool_nodes_present(self, alias, location, name, port, nodes):
|
||||
"""
|
||||
Checks to see if the provided list of nodes exist for the pool and add the missing nodes to the pool
|
||||
:param alias: The account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param name: the name of the load balancer
|
||||
:param port: the port that the load balancer will listen on
|
||||
:param nodes: the list of nodes to be added
|
||||
:return: (changed, result) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
"""
|
||||
changed = False
|
||||
lb_exists = self._loadbalancer_exists(name=name)
|
||||
if lb_exists:
|
||||
lb_id = self._get_loadbalancer_id(name=name)
|
||||
pool_id = self._loadbalancerpool_exists(
|
||||
alias=alias,
|
||||
location=location,
|
||||
port=port,
|
||||
lb_id=lb_id)
|
||||
if pool_id:
|
||||
changed, result = self.add_lbpool_nodes(alias=alias,
|
||||
location=location,
|
||||
lb_id=lb_id,
|
||||
pool_id=pool_id,
|
||||
nodes_to_add=nodes)
|
||||
else:
|
||||
result = "Pool doesn't exist"
|
||||
else:
|
||||
result = "Load balancer doesn't Exist"
|
||||
return changed, result
|
||||
|
||||
def ensure_lbpool_nodes_absent(self, alias, location, name, port, nodes):
|
||||
"""
|
||||
Checks to see if the provided list of nodes exist for the pool and removes them if found any
|
||||
:param alias: The account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param name: the name of the load balancer
|
||||
:param port: the port that the load balancer will listen on
|
||||
:param nodes: the list of nodes to be removed
|
||||
:return: (changed, result) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
"""
|
||||
changed = False
|
||||
lb_exists = self._loadbalancer_exists(name=name)
|
||||
if lb_exists:
|
||||
lb_id = self._get_loadbalancer_id(name=name)
|
||||
pool_id = self._loadbalancerpool_exists(
|
||||
alias=alias,
|
||||
location=location,
|
||||
port=port,
|
||||
lb_id=lb_id)
|
||||
if pool_id:
|
||||
changed, result = self.remove_lbpool_nodes(alias=alias,
|
||||
location=location,
|
||||
lb_id=lb_id,
|
||||
pool_id=pool_id,
|
||||
nodes_to_remove=nodes)
|
||||
else:
|
||||
result = "Pool doesn't exist"
|
||||
else:
|
||||
result = "Load balancer doesn't Exist"
|
||||
return changed, result
|
||||
|
||||
def create_loadbalancer(self, name, alias, location, description, status):
|
||||
"""
|
||||
Create a loadbalancer w/ params
|
||||
:param name: Name of loadbalancer
|
||||
:param alias: Alias of account
|
||||
:param location: Datacenter
|
||||
:param description: Description for loadbalancer to be created
|
||||
:param status: Enabled / Disabled
|
||||
:return: result: The result from the CLC API call
|
||||
"""
|
||||
result = None
|
||||
try:
|
||||
result = self.clc.v2.API.Call('POST',
|
||||
'/v2/sharedLoadBalancers/%s/%s' % (alias,
|
||||
location),
|
||||
json.dumps({"name": name,
|
||||
"description": description,
|
||||
"status": status}))
|
||||
sleep(1)
|
||||
except APIFailedResponse as e:
|
||||
self.module.fail_json(
|
||||
msg='Unable to create load balancer "{0}". {1}'.format(
|
||||
name, str(e.response_text)))
|
||||
return result
|
||||
|
||||
def create_loadbalancerpool(
|
||||
self, alias, location, lb_id, method, persistence, port):
|
||||
"""
|
||||
Creates a pool on the provided load balancer
|
||||
:param alias: the account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param lb_id: the id string of the load balancer
|
||||
:param method: the load balancing method
|
||||
:param persistence: the load balancing persistence type
|
||||
:param port: the port that the load balancer will listen on
|
||||
:return: result: The result from the create API call
|
||||
"""
|
||||
result = None
|
||||
try:
|
||||
result = self.clc.v2.API.Call(
|
||||
'POST', '/v2/sharedLoadBalancers/%s/%s/%s/pools' %
|
||||
(alias, location, lb_id), json.dumps(
|
||||
{
|
||||
"port": port, "method": method, "persistence": persistence
|
||||
}))
|
||||
except APIFailedResponse as e:
|
||||
self.module.fail_json(
|
||||
msg='Unable to create pool for load balancer id "{0}". {1}'.format(
|
||||
lb_id, str(e.response_text)))
|
||||
return result
|
||||
|
||||
def delete_loadbalancer(self, alias, location, name):
|
||||
"""
|
||||
Delete CLC loadbalancer
|
||||
:param alias: Alias for account
|
||||
:param location: Datacenter
|
||||
:param name: Name of the loadbalancer to delete
|
||||
:return: result: The result from the CLC API call
|
||||
"""
|
||||
result = None
|
||||
lb_id = self._get_loadbalancer_id(name=name)
|
||||
try:
|
||||
result = self.clc.v2.API.Call(
|
||||
'DELETE', '/v2/sharedLoadBalancers/%s/%s/%s' %
|
||||
(alias, location, lb_id))
|
||||
except APIFailedResponse as e:
|
||||
self.module.fail_json(
|
||||
msg='Unable to delete load balancer "{0}". {1}'.format(
|
||||
name, str(e.response_text)))
|
||||
return result
|
||||
|
||||
def delete_loadbalancerpool(self, alias, location, lb_id, pool_id):
|
||||
"""
|
||||
Delete the pool on the provided load balancer
|
||||
:param alias: The account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param lb_id: the id string of the load balancer
|
||||
:param pool_id: the id string of the load balancer pool
|
||||
:return: result: The result from the delete API call
|
||||
"""
|
||||
result = None
|
||||
try:
|
||||
result = self.clc.v2.API.Call(
|
||||
'DELETE', '/v2/sharedLoadBalancers/%s/%s/%s/pools/%s' %
|
||||
(alias, location, lb_id, pool_id))
|
||||
except APIFailedResponse as e:
|
||||
self.module.fail_json(
|
||||
msg='Unable to delete pool for load balancer id "{0}". {1}'.format(
|
||||
lb_id, str(e.response_text)))
|
||||
return result
|
||||
|
||||
def _get_loadbalancer_id(self, name):
|
||||
"""
|
||||
Retrieves unique ID of loadbalancer
|
||||
:param name: Name of loadbalancer
|
||||
:return: Unique ID of the loadbalancer
|
||||
"""
|
||||
id = None
|
||||
for lb in self.lb_dict:
|
||||
if lb.get('name') == name:
|
||||
id = lb.get('id')
|
||||
return id
|
||||
|
||||
def _get_loadbalancer_list(self, alias, location):
|
||||
"""
|
||||
Retrieve a list of loadbalancers
|
||||
:param alias: Alias for account
|
||||
:param location: Datacenter
|
||||
:return: JSON data for all loadbalancers at datacenter
|
||||
"""
|
||||
result = None
|
||||
try:
|
||||
result = self.clc.v2.API.Call(
|
||||
'GET', '/v2/sharedLoadBalancers/%s/%s' % (alias, location))
|
||||
except APIFailedResponse as e:
|
||||
self.module.fail_json(
|
||||
msg='Unable to fetch load balancers for account: {0}. {1}'.format(
|
||||
alias, str(e.response_text)))
|
||||
return result
|
||||
|
||||
def _loadbalancer_exists(self, name):
|
||||
"""
|
||||
Verify a loadbalancer exists
|
||||
:param name: Name of loadbalancer
|
||||
:return: False or the ID of the existing loadbalancer
|
||||
"""
|
||||
result = False
|
||||
|
||||
for lb in self.lb_dict:
|
||||
if lb.get('name') == name:
|
||||
result = lb.get('id')
|
||||
return result
|
||||
|
||||
def _loadbalancerpool_exists(self, alias, location, port, lb_id):
|
||||
"""
|
||||
Checks to see if a pool exists on the specified port on the provided load balancer
|
||||
:param alias: the account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param port: the port to check and see if it exists
|
||||
:param lb_id: the id string of the provided load balancer
|
||||
:return: result: The id string of the pool or False
|
||||
"""
|
||||
result = False
|
||||
try:
|
||||
pool_list = self.clc.v2.API.Call(
|
||||
'GET', '/v2/sharedLoadBalancers/%s/%s/%s/pools' %
|
||||
(alias, location, lb_id))
|
||||
except APIFailedResponse as e:
|
||||
return self.module.fail_json(
|
||||
msg='Unable to fetch the load balancer pools for for load balancer id: {0}. {1}'.format(
|
||||
lb_id, str(e.response_text)))
|
||||
for pool in pool_list:
|
||||
if int(pool.get('port')) == int(port):
|
||||
result = pool.get('id')
|
||||
return result
|
||||
|
||||
def _loadbalancerpool_nodes_exists(
|
||||
self, alias, location, lb_id, pool_id, nodes_to_check):
|
||||
"""
|
||||
Checks to see if a set of nodes exists on the specified port on the provided load balancer
|
||||
:param alias: the account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param lb_id: the id string of the provided load balancer
|
||||
:param pool_id: the id string of the load balancer pool
|
||||
:param nodes_to_check: the list of nodes to check for
|
||||
:return: result: True / False indicating if the given nodes exist
|
||||
"""
|
||||
result = False
|
||||
nodes = self._get_lbpool_nodes(alias, location, lb_id, pool_id)
|
||||
for node in nodes_to_check:
|
||||
if not node.get('status'):
|
||||
node['status'] = 'enabled'
|
||||
if node in nodes:
|
||||
result = True
|
||||
else:
|
||||
result = False
|
||||
return result
|
||||
|
||||
def set_loadbalancernodes(self, alias, location, lb_id, pool_id, nodes):
|
||||
"""
|
||||
Updates nodes to the provided pool
|
||||
:param alias: the account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param lb_id: the id string of the load balancer
|
||||
:param pool_id: the id string of the pool
|
||||
:param nodes: a list of dictionaries containing the nodes to set
|
||||
:return: result: The result from the CLC API call
|
||||
"""
|
||||
result = None
|
||||
if not lb_id:
|
||||
return result
|
||||
if not self.module.check_mode:
|
||||
try:
|
||||
result = self.clc.v2.API.Call('PUT',
|
||||
'/v2/sharedLoadBalancers/%s/%s/%s/pools/%s/nodes'
|
||||
% (alias, location, lb_id, pool_id), json.dumps(nodes))
|
||||
except APIFailedResponse as e:
|
||||
self.module.fail_json(
|
||||
msg='Unable to set nodes for the load balancer pool id "{0}". {1}'.format(
|
||||
pool_id, str(e.response_text)))
|
||||
return result
|
||||
|
||||
def add_lbpool_nodes(self, alias, location, lb_id, pool_id, nodes_to_add):
|
||||
"""
|
||||
Add nodes to the provided pool
|
||||
:param alias: the account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param lb_id: the id string of the load balancer
|
||||
:param pool_id: the id string of the pool
|
||||
:param nodes_to_add: a list of dictionaries containing the nodes to add
|
||||
:return: (changed, result) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
"""
|
||||
changed = False
|
||||
result = {}
|
||||
nodes = self._get_lbpool_nodes(alias, location, lb_id, pool_id)
|
||||
for node in nodes_to_add:
|
||||
if not node.get('status'):
|
||||
node['status'] = 'enabled'
|
||||
if node not in nodes:
|
||||
changed = True
|
||||
nodes.append(node)
|
||||
if changed is True and not self.module.check_mode:
|
||||
result = self.set_loadbalancernodes(
|
||||
alias,
|
||||
location,
|
||||
lb_id,
|
||||
pool_id,
|
||||
nodes)
|
||||
return changed, result
|
||||
|
||||
def remove_lbpool_nodes(
|
||||
self, alias, location, lb_id, pool_id, nodes_to_remove):
|
||||
"""
|
||||
Removes nodes from the provided pool
|
||||
:param alias: the account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param lb_id: the id string of the load balancer
|
||||
:param pool_id: the id string of the pool
|
||||
:param nodes_to_remove: a list of dictionaries containing the nodes to remove
|
||||
:return: (changed, result) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
"""
|
||||
changed = False
|
||||
result = {}
|
||||
nodes = self._get_lbpool_nodes(alias, location, lb_id, pool_id)
|
||||
for node in nodes_to_remove:
|
||||
if not node.get('status'):
|
||||
node['status'] = 'enabled'
|
||||
if node in nodes:
|
||||
changed = True
|
||||
nodes.remove(node)
|
||||
if changed is True and not self.module.check_mode:
|
||||
result = self.set_loadbalancernodes(
|
||||
alias,
|
||||
location,
|
||||
lb_id,
|
||||
pool_id,
|
||||
nodes)
|
||||
return changed, result
|
||||
|
||||
def _get_lbpool_nodes(self, alias, location, lb_id, pool_id):
|
||||
"""
|
||||
Return the list of nodes available to the provided load balancer pool
|
||||
:param alias: the account alias
|
||||
:param location: the datacenter the load balancer resides in
|
||||
:param lb_id: the id string of the load balancer
|
||||
:param pool_id: the id string of the pool
|
||||
:return: result: The list of nodes
|
||||
"""
|
||||
result = None
|
||||
try:
|
||||
result = self.clc.v2.API.Call('GET',
|
||||
'/v2/sharedLoadBalancers/%s/%s/%s/pools/%s/nodes'
|
||||
% (alias, location, lb_id, pool_id))
|
||||
except APIFailedResponse as e:
|
||||
self.module.fail_json(
|
||||
msg='Unable to fetch list of available nodes for load balancer pool id: {0}. {1}'.format(
|
||||
pool_id, str(e.response_text)))
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def define_argument_spec():
|
||||
"""
|
||||
Define the argument spec for the ansible module
|
||||
:return: argument spec dictionary
|
||||
"""
|
||||
argument_spec = dict(
|
||||
name=dict(required=True),
|
||||
description=dict(),
|
||||
location=dict(required=True),
|
||||
alias=dict(required=True),
|
||||
port=dict(choices=[80, 443]),
|
||||
method=dict(choices=['leastConnection', 'roundRobin']),
|
||||
persistence=dict(choices=['standard', 'sticky']),
|
||||
nodes=dict(type='list', default=[], elements='dict'),
|
||||
status=dict(default='enabled', choices=['enabled', 'disabled']),
|
||||
state=dict(
|
||||
default='present',
|
||||
choices=[
|
||||
'present',
|
||||
'absent',
|
||||
'port_absent',
|
||||
'nodes_present',
|
||||
'nodes_absent'])
|
||||
)
|
||||
return argument_spec
|
||||
|
||||
def _set_clc_credentials_from_env(self):
|
||||
"""
|
||||
Set the CLC Credentials on the sdk by reading environment variables
|
||||
:return: none
|
||||
"""
|
||||
env = os.environ
|
||||
v2_api_token = env.get('CLC_V2_API_TOKEN', False)
|
||||
v2_api_username = env.get('CLC_V2_API_USERNAME', False)
|
||||
v2_api_passwd = env.get('CLC_V2_API_PASSWD', False)
|
||||
clc_alias = env.get('CLC_ACCT_ALIAS', False)
|
||||
api_url = env.get('CLC_V2_API_URL', False)
|
||||
|
||||
if api_url:
|
||||
self.clc.defaults.ENDPOINT_URL_V2 = api_url
|
||||
|
||||
if v2_api_token and clc_alias:
|
||||
self.clc._LOGIN_TOKEN_V2 = v2_api_token
|
||||
self.clc._V2_ENABLED = True
|
||||
self.clc.ALIAS = clc_alias
|
||||
elif v2_api_username and v2_api_passwd:
|
||||
self.clc.v2.SetCredentials(
|
||||
api_username=v2_api_username,
|
||||
api_passwd=v2_api_passwd)
|
||||
else:
|
||||
return self.module.fail_json(
|
||||
msg="You must set the CLC_V2_API_USERNAME and CLC_V2_API_PASSWD "
|
||||
"environment variables")
|
||||
|
||||
@staticmethod
|
||||
def _set_user_agent(clc):
|
||||
if hasattr(clc, 'SetRequestsSession'):
|
||||
agent_string = "ClcAnsibleModule/" + __version__
|
||||
ses = requests.Session()
|
||||
ses.headers.update({"Api-Client": agent_string})
|
||||
ses.headers['User-Agent'] += " " + agent_string
|
||||
clc.SetRequestsSession(ses)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
The main function. Instantiates the module and calls process_request.
|
||||
:return: none
|
||||
"""
|
||||
module = AnsibleModule(argument_spec=ClcLoadBalancer.define_argument_spec(),
|
||||
supports_check_mode=True)
|
||||
clc_loadbalancer = ClcLoadBalancer(module)
|
||||
clc_loadbalancer.process_request()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
961
plugins/modules/clc_modify_server.py
Normal file
961
plugins/modules/clc_modify_server.py
Normal file
@@ -0,0 +1,961 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2015 CenturyLink
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: clc_modify_server
|
||||
short_description: Modify servers in CenturyLink Cloud
|
||||
description:
|
||||
- An Ansible module to modify servers in CenturyLink Cloud.
|
||||
deprecated:
|
||||
removed_in: 11.0.0
|
||||
why: >
|
||||
Lumen Public Cloud (formerly known as CenturyLink Cloud) has gone End-of-Life in September 2023.
|
||||
See more at U(https://www.ctl.io/knowledge-base/release-notes/2023/lumen-public-cloud-platform-end-of-life-notice/?).
|
||||
alternative: There is none.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
- community.general.clc
|
||||
author:
|
||||
- "CLC Runner (@clc-runner)"
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
options:
|
||||
server_ids:
|
||||
description:
|
||||
- A list of server IDs to modify.
|
||||
type: list
|
||||
required: true
|
||||
elements: str
|
||||
cpu:
|
||||
description:
|
||||
- How many CPUs to update on the server.
|
||||
type: str
|
||||
memory:
|
||||
description:
|
||||
- Memory (in GB) to set to the server.
|
||||
type: str
|
||||
anti_affinity_policy_id:
|
||||
description:
|
||||
- The anti affinity policy ID to be set for a hyper scale server. This is mutually exclusive with O(anti_affinity_policy_name).
|
||||
type: str
|
||||
anti_affinity_policy_name:
|
||||
description:
|
||||
- The anti affinity policy name to be set for a hyper scale server. This is mutually exclusive with O(anti_affinity_policy_id).
|
||||
type: str
|
||||
alert_policy_id:
|
||||
description:
|
||||
- The alert policy ID to be associated to the server. This is mutually exclusive with O(alert_policy_name).
|
||||
type: str
|
||||
alert_policy_name:
|
||||
description:
|
||||
- The alert policy name to be associated to the server. This is mutually exclusive with O(alert_policy_id).
|
||||
type: str
|
||||
state:
|
||||
description:
|
||||
- The state to insure that the provided resources are in.
|
||||
type: str
|
||||
default: 'present'
|
||||
choices: ['present', 'absent']
|
||||
wait:
|
||||
description:
|
||||
- Whether to wait for the provisioning tasks to finish before returning.
|
||||
type: bool
|
||||
default: true
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
# Note - You must set the CLC_V2_API_USERNAME And CLC_V2_API_PASSWD Environment variables before running these examples
|
||||
|
||||
- name: Set the cpu count to 4 on a server
|
||||
community.general.clc_modify_server:
|
||||
server_ids:
|
||||
- UC1TESTSVR01
|
||||
- UC1TESTSVR02
|
||||
cpu: 4
|
||||
state: present
|
||||
|
||||
- name: Set the memory to 8GB on a server
|
||||
community.general.clc_modify_server:
|
||||
server_ids:
|
||||
- UC1TESTSVR01
|
||||
- UC1TESTSVR02
|
||||
memory: 8
|
||||
state: present
|
||||
|
||||
- name: Set the anti affinity policy on a server
|
||||
community.general.clc_modify_server:
|
||||
server_ids:
|
||||
- UC1TESTSVR01
|
||||
- UC1TESTSVR02
|
||||
anti_affinity_policy_name: 'aa_policy'
|
||||
state: present
|
||||
|
||||
- name: Remove the anti affinity policy on a server
|
||||
community.general.clc_modify_server:
|
||||
server_ids:
|
||||
- UC1TESTSVR01
|
||||
- UC1TESTSVR02
|
||||
anti_affinity_policy_name: 'aa_policy'
|
||||
state: absent
|
||||
|
||||
- name: Add the alert policy on a server
|
||||
community.general.clc_modify_server:
|
||||
server_ids:
|
||||
- UC1TESTSVR01
|
||||
- UC1TESTSVR02
|
||||
alert_policy_name: 'alert_policy'
|
||||
state: present
|
||||
|
||||
- name: Remove the alert policy on a server
|
||||
community.general.clc_modify_server:
|
||||
server_ids:
|
||||
- UC1TESTSVR01
|
||||
- UC1TESTSVR02
|
||||
alert_policy_name: 'alert_policy'
|
||||
state: absent
|
||||
|
||||
- name: Ret the memory to 16GB and cpu to 8 core on a lust if servers
|
||||
community.general.clc_modify_server:
|
||||
server_ids:
|
||||
- UC1TESTSVR01
|
||||
- UC1TESTSVR02
|
||||
cpu: 8
|
||||
memory: 16
|
||||
state: present
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
server_ids:
|
||||
description: The list of server IDs that are changed.
|
||||
returned: success
|
||||
type: list
|
||||
sample: ["UC1TEST-SVR01", "UC1TEST-SVR02"]
|
||||
servers:
|
||||
description: The list of server objects that are changed.
|
||||
returned: success
|
||||
type: list
|
||||
sample:
|
||||
[
|
||||
{
|
||||
"changeInfo":{
|
||||
"createdBy":"service.wfad",
|
||||
"createdDate":1438196820,
|
||||
"modifiedBy":"service.wfad",
|
||||
"modifiedDate":1438196820
|
||||
},
|
||||
"description":"test-server",
|
||||
"details":{
|
||||
"alertPolicies":[
|
||||
|
||||
],
|
||||
"cpu":1,
|
||||
"customFields":[
|
||||
|
||||
],
|
||||
"diskCount":3,
|
||||
"disks":[
|
||||
{
|
||||
"id":"0:0",
|
||||
"partitionPaths":[
|
||||
|
||||
],
|
||||
"sizeGB":1
|
||||
},
|
||||
{
|
||||
"id":"0:1",
|
||||
"partitionPaths":[
|
||||
|
||||
],
|
||||
"sizeGB":2
|
||||
},
|
||||
{
|
||||
"id":"0:2",
|
||||
"partitionPaths":[
|
||||
|
||||
],
|
||||
"sizeGB":14
|
||||
}
|
||||
],
|
||||
"hostName":"",
|
||||
"inMaintenanceMode":false,
|
||||
"ipAddresses":[
|
||||
{
|
||||
"internal":"10.1.1.1"
|
||||
}
|
||||
],
|
||||
"memoryGB":1,
|
||||
"memoryMB":1024,
|
||||
"partitions":[
|
||||
|
||||
],
|
||||
"powerState":"started",
|
||||
"snapshots":[
|
||||
|
||||
],
|
||||
"storageGB":17
|
||||
},
|
||||
"groupId":"086ac1dfe0b6411989e8d1b77c4065f0",
|
||||
"id":"test-server",
|
||||
"ipaddress":"10.120.45.23",
|
||||
"isTemplate":false,
|
||||
"links":[
|
||||
{
|
||||
"href":"/v2/servers/wfad/test-server",
|
||||
"id":"test-server",
|
||||
"rel":"self",
|
||||
"verbs":[
|
||||
"GET",
|
||||
"PATCH",
|
||||
"DELETE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"href":"/v2/groups/wfad/086ac1dfe0b6411989e8d1b77c4065f0",
|
||||
"id":"086ac1dfe0b6411989e8d1b77c4065f0",
|
||||
"rel":"group"
|
||||
},
|
||||
{
|
||||
"href":"/v2/accounts/wfad",
|
||||
"id":"wfad",
|
||||
"rel":"account"
|
||||
},
|
||||
{
|
||||
"href":"/v2/billing/wfad/serverPricing/test-server",
|
||||
"rel":"billing"
|
||||
},
|
||||
{
|
||||
"href":"/v2/servers/wfad/test-server/publicIPAddresses",
|
||||
"rel":"publicIPAddresses",
|
||||
"verbs":[
|
||||
"POST"
|
||||
]
|
||||
},
|
||||
{
|
||||
"href":"/v2/servers/wfad/test-server/credentials",
|
||||
"rel":"credentials"
|
||||
},
|
||||
{
|
||||
"href":"/v2/servers/wfad/test-server/statistics",
|
||||
"rel":"statistics"
|
||||
},
|
||||
{
|
||||
"href":"/v2/servers/wfad/510ec21ae82d4dc89d28479753bf736a/upcomingScheduledActivities",
|
||||
"rel":"upcomingScheduledActivities"
|
||||
},
|
||||
{
|
||||
"href":"/v2/servers/wfad/510ec21ae82d4dc89d28479753bf736a/scheduledActivities",
|
||||
"rel":"scheduledActivities",
|
||||
"verbs":[
|
||||
"GET",
|
||||
"POST"
|
||||
]
|
||||
},
|
||||
{
|
||||
"href":"/v2/servers/wfad/test-server/capabilities",
|
||||
"rel":"capabilities"
|
||||
},
|
||||
{
|
||||
"href":"/v2/servers/wfad/test-server/alertPolicies",
|
||||
"rel":"alertPolicyMappings",
|
||||
"verbs":[
|
||||
"POST"
|
||||
]
|
||||
},
|
||||
{
|
||||
"href":"/v2/servers/wfad/test-server/antiAffinityPolicy",
|
||||
"rel":"antiAffinityPolicyMapping",
|
||||
"verbs":[
|
||||
"PUT",
|
||||
"DELETE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"href":"/v2/servers/wfad/test-server/cpuAutoscalePolicy",
|
||||
"rel":"cpuAutoscalePolicyMapping",
|
||||
"verbs":[
|
||||
"PUT",
|
||||
"DELETE"
|
||||
]
|
||||
}
|
||||
],
|
||||
"locationId":"UC1",
|
||||
"name":"test-server",
|
||||
"os":"ubuntu14_64Bit",
|
||||
"osType":"Ubuntu 14 64-bit",
|
||||
"status":"active",
|
||||
"storageType":"standard",
|
||||
"type":"standard"
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
||||
__version__ = '${version}'
|
||||
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
REQUESTS_IMP_ERR = None
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
REQUESTS_IMP_ERR = traceback.format_exc()
|
||||
REQUESTS_FOUND = False
|
||||
else:
|
||||
REQUESTS_FOUND = True
|
||||
|
||||
#
|
||||
# Requires the clc-python-sdk.
|
||||
# sudo pip install clc-sdk
|
||||
#
|
||||
CLC_IMP_ERR = None
|
||||
try:
|
||||
import clc as clc_sdk
|
||||
from clc import CLCException
|
||||
from clc import APIFailedResponse
|
||||
except ImportError:
|
||||
CLC_IMP_ERR = traceback.format_exc()
|
||||
CLC_FOUND = False
|
||||
clc_sdk = None
|
||||
else:
|
||||
CLC_FOUND = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
|
||||
class ClcModifyServer:
|
||||
clc = clc_sdk
|
||||
|
||||
def __init__(self, module):
|
||||
"""
|
||||
Construct module
|
||||
"""
|
||||
self.clc = clc_sdk
|
||||
self.module = module
|
||||
|
||||
if not CLC_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR)
|
||||
if not REQUESTS_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR)
|
||||
if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'):
|
||||
self.module.fail_json(
|
||||
msg='requests library version should be >= 2.5.0')
|
||||
|
||||
self._set_user_agent(self.clc)
|
||||
|
||||
def process_request(self):
|
||||
"""
|
||||
Process the request - Main Code Path
|
||||
:return: Returns with either an exit_json or fail_json
|
||||
"""
|
||||
self._set_clc_credentials_from_env()
|
||||
|
||||
p = self.module.params
|
||||
cpu = p.get('cpu')
|
||||
memory = p.get('memory')
|
||||
state = p.get('state')
|
||||
if state == 'absent' and (cpu or memory):
|
||||
return self.module.fail_json(
|
||||
msg='\'absent\' state is not supported for \'cpu\' and \'memory\' arguments')
|
||||
|
||||
server_ids = p['server_ids']
|
||||
if not isinstance(server_ids, list):
|
||||
return self.module.fail_json(
|
||||
msg='server_ids needs to be a list of instances to modify: %s' %
|
||||
server_ids)
|
||||
|
||||
(changed, server_dict_array, changed_server_ids) = self._modify_servers(
|
||||
server_ids=server_ids)
|
||||
|
||||
self.module.exit_json(
|
||||
changed=changed,
|
||||
server_ids=changed_server_ids,
|
||||
servers=server_dict_array)
|
||||
|
||||
@staticmethod
|
||||
def _define_module_argument_spec():
|
||||
"""
|
||||
Define the argument spec for the ansible module
|
||||
:return: argument spec dictionary
|
||||
"""
|
||||
argument_spec = dict(
|
||||
server_ids=dict(type='list', required=True, elements='str'),
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
cpu=dict(),
|
||||
memory=dict(),
|
||||
anti_affinity_policy_id=dict(),
|
||||
anti_affinity_policy_name=dict(),
|
||||
alert_policy_id=dict(),
|
||||
alert_policy_name=dict(),
|
||||
wait=dict(type='bool', default=True)
|
||||
)
|
||||
mutually_exclusive = [
|
||||
['anti_affinity_policy_id', 'anti_affinity_policy_name'],
|
||||
['alert_policy_id', 'alert_policy_name']
|
||||
]
|
||||
return {"argument_spec": argument_spec,
|
||||
"mutually_exclusive": mutually_exclusive}
|
||||
|
||||
def _set_clc_credentials_from_env(self):
|
||||
"""
|
||||
Set the CLC Credentials on the sdk by reading environment variables
|
||||
:return: none
|
||||
"""
|
||||
env = os.environ
|
||||
v2_api_token = env.get('CLC_V2_API_TOKEN', False)
|
||||
v2_api_username = env.get('CLC_V2_API_USERNAME', False)
|
||||
v2_api_passwd = env.get('CLC_V2_API_PASSWD', False)
|
||||
clc_alias = env.get('CLC_ACCT_ALIAS', False)
|
||||
api_url = env.get('CLC_V2_API_URL', False)
|
||||
|
||||
if api_url:
|
||||
self.clc.defaults.ENDPOINT_URL_V2 = api_url
|
||||
|
||||
if v2_api_token and clc_alias:
|
||||
self.clc._LOGIN_TOKEN_V2 = v2_api_token
|
||||
self.clc._V2_ENABLED = True
|
||||
self.clc.ALIAS = clc_alias
|
||||
elif v2_api_username and v2_api_passwd:
|
||||
self.clc.v2.SetCredentials(
|
||||
api_username=v2_api_username,
|
||||
api_passwd=v2_api_passwd)
|
||||
else:
|
||||
return self.module.fail_json(
|
||||
msg="You must set the CLC_V2_API_USERNAME and CLC_V2_API_PASSWD "
|
||||
"environment variables")
|
||||
|
||||
def _get_servers_from_clc(self, server_list, message):
|
||||
"""
|
||||
Internal function to fetch list of CLC server objects from a list of server ids
|
||||
:param server_list: The list of server ids
|
||||
:param message: the error message to throw in case of any error
|
||||
:return the list of CLC server objects
|
||||
"""
|
||||
try:
|
||||
return self.clc.v2.Servers(server_list).servers
|
||||
except CLCException as ex:
|
||||
return self.module.fail_json(msg=message + ': %s' % ex.message)
|
||||
|
||||
def _modify_servers(self, server_ids):
|
||||
"""
|
||||
modify the servers configuration on the provided list
|
||||
:param server_ids: list of servers to modify
|
||||
:return: a list of dictionaries with server information about the servers that were modified
|
||||
"""
|
||||
p = self.module.params
|
||||
state = p.get('state')
|
||||
server_params = {
|
||||
'cpu': p.get('cpu'),
|
||||
'memory': p.get('memory'),
|
||||
'anti_affinity_policy_id': p.get('anti_affinity_policy_id'),
|
||||
'anti_affinity_policy_name': p.get('anti_affinity_policy_name'),
|
||||
'alert_policy_id': p.get('alert_policy_id'),
|
||||
'alert_policy_name': p.get('alert_policy_name'),
|
||||
}
|
||||
changed = False
|
||||
server_changed = False
|
||||
aa_changed = False
|
||||
ap_changed = False
|
||||
server_dict_array = []
|
||||
result_server_ids = []
|
||||
request_list = []
|
||||
changed_servers = []
|
||||
|
||||
if not isinstance(server_ids, list) or len(server_ids) < 1:
|
||||
return self.module.fail_json(
|
||||
msg='server_ids should be a list of servers, aborting')
|
||||
|
||||
servers = self._get_servers_from_clc(
|
||||
server_ids,
|
||||
'Failed to obtain server list from the CLC API')
|
||||
for server in servers:
|
||||
if state == 'present':
|
||||
server_changed, server_result = self._ensure_server_config(
|
||||
server, server_params)
|
||||
if server_result:
|
||||
request_list.append(server_result)
|
||||
aa_changed = self._ensure_aa_policy_present(
|
||||
server,
|
||||
server_params)
|
||||
ap_changed = self._ensure_alert_policy_present(
|
||||
server,
|
||||
server_params)
|
||||
elif state == 'absent':
|
||||
aa_changed = self._ensure_aa_policy_absent(
|
||||
server,
|
||||
server_params)
|
||||
ap_changed = self._ensure_alert_policy_absent(
|
||||
server,
|
||||
server_params)
|
||||
if server_changed or aa_changed or ap_changed:
|
||||
changed_servers.append(server)
|
||||
changed = True
|
||||
|
||||
self._wait_for_requests(self.module, request_list)
|
||||
self._refresh_servers(self.module, changed_servers)
|
||||
|
||||
for server in changed_servers:
|
||||
server_dict_array.append(server.data)
|
||||
result_server_ids.append(server.id)
|
||||
|
||||
return changed, server_dict_array, result_server_ids
|
||||
|
||||
def _ensure_server_config(
|
||||
self, server, server_params):
|
||||
"""
|
||||
ensures the server is updated with the provided cpu and memory
|
||||
:param server: the CLC server object
|
||||
:param server_params: the dictionary of server parameters
|
||||
:return: (changed, group) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
"""
|
||||
cpu = server_params.get('cpu')
|
||||
memory = server_params.get('memory')
|
||||
changed = False
|
||||
result = None
|
||||
|
||||
if not cpu:
|
||||
cpu = server.cpu
|
||||
if not memory:
|
||||
memory = server.memory
|
||||
if memory != server.memory or cpu != server.cpu:
|
||||
if not self.module.check_mode:
|
||||
result = self._modify_clc_server(
|
||||
self.clc,
|
||||
self.module,
|
||||
server.id,
|
||||
cpu,
|
||||
memory)
|
||||
changed = True
|
||||
return changed, result
|
||||
|
||||
@staticmethod
|
||||
def _modify_clc_server(clc, module, server_id, cpu, memory):
|
||||
"""
|
||||
Modify the memory or CPU of a clc server.
|
||||
:param clc: the clc-sdk instance to use
|
||||
:param module: the AnsibleModule object
|
||||
:param server_id: id of the server to modify
|
||||
:param cpu: the new cpu value
|
||||
:param memory: the new memory value
|
||||
:return: the result of CLC API call
|
||||
"""
|
||||
result = None
|
||||
acct_alias = clc.v2.Account.GetAlias()
|
||||
try:
|
||||
# Update the server configuration
|
||||
job_obj = clc.v2.API.Call('PATCH',
|
||||
'servers/%s/%s' % (acct_alias,
|
||||
server_id),
|
||||
json.dumps([{"op": "set",
|
||||
"member": "memory",
|
||||
"value": memory},
|
||||
{"op": "set",
|
||||
"member": "cpu",
|
||||
"value": cpu}]))
|
||||
result = clc.v2.Requests(job_obj)
|
||||
except APIFailedResponse as ex:
|
||||
module.fail_json(
|
||||
msg='Unable to update the server configuration for server : "{0}". {1}'.format(
|
||||
server_id, str(ex.response_text)))
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _wait_for_requests(module, request_list):
|
||||
"""
|
||||
Block until server provisioning requests are completed.
|
||||
:param module: the AnsibleModule object
|
||||
:param request_list: a list of clc-sdk.Request instances
|
||||
:return: none
|
||||
"""
|
||||
wait = module.params.get('wait')
|
||||
if wait:
|
||||
# Requests.WaitUntilComplete() returns the count of failed requests
|
||||
failed_requests_count = sum(
|
||||
[request.WaitUntilComplete() for request in request_list])
|
||||
|
||||
if failed_requests_count > 0:
|
||||
module.fail_json(
|
||||
msg='Unable to process modify server request')
|
||||
|
||||
@staticmethod
|
||||
def _refresh_servers(module, servers):
|
||||
"""
|
||||
Loop through a list of servers and refresh them.
|
||||
:param module: the AnsibleModule object
|
||||
:param servers: list of clc-sdk.Server instances to refresh
|
||||
:return: none
|
||||
"""
|
||||
for server in servers:
|
||||
try:
|
||||
server.Refresh()
|
||||
except CLCException as ex:
|
||||
module.fail_json(msg='Unable to refresh the server {0}. {1}'.format(
|
||||
server.id, ex.message
|
||||
))
|
||||
|
||||
def _ensure_aa_policy_present(
|
||||
self, server, server_params):
|
||||
"""
|
||||
ensures the server is updated with the provided anti affinity policy
|
||||
:param server: the CLC server object
|
||||
:param server_params: the dictionary of server parameters
|
||||
:return: (changed, group) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
"""
|
||||
changed = False
|
||||
acct_alias = self.clc.v2.Account.GetAlias()
|
||||
|
||||
aa_policy_id = server_params.get('anti_affinity_policy_id')
|
||||
aa_policy_name = server_params.get('anti_affinity_policy_name')
|
||||
if not aa_policy_id and aa_policy_name:
|
||||
aa_policy_id = self._get_aa_policy_id_by_name(
|
||||
self.clc,
|
||||
self.module,
|
||||
acct_alias,
|
||||
aa_policy_name)
|
||||
current_aa_policy_id = self._get_aa_policy_id_of_server(
|
||||
self.clc,
|
||||
self.module,
|
||||
acct_alias,
|
||||
server.id)
|
||||
|
||||
if aa_policy_id and aa_policy_id != current_aa_policy_id:
|
||||
self._modify_aa_policy(
|
||||
self.clc,
|
||||
self.module,
|
||||
acct_alias,
|
||||
server.id,
|
||||
aa_policy_id)
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
def _ensure_aa_policy_absent(
|
||||
self, server, server_params):
|
||||
"""
|
||||
ensures the provided anti affinity policy is removed from the server
|
||||
:param server: the CLC server object
|
||||
:param server_params: the dictionary of server parameters
|
||||
:return: (changed, group) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
"""
|
||||
changed = False
|
||||
acct_alias = self.clc.v2.Account.GetAlias()
|
||||
aa_policy_id = server_params.get('anti_affinity_policy_id')
|
||||
aa_policy_name = server_params.get('anti_affinity_policy_name')
|
||||
if not aa_policy_id and aa_policy_name:
|
||||
aa_policy_id = self._get_aa_policy_id_by_name(
|
||||
self.clc,
|
||||
self.module,
|
||||
acct_alias,
|
||||
aa_policy_name)
|
||||
current_aa_policy_id = self._get_aa_policy_id_of_server(
|
||||
self.clc,
|
||||
self.module,
|
||||
acct_alias,
|
||||
server.id)
|
||||
|
||||
if aa_policy_id and aa_policy_id == current_aa_policy_id:
|
||||
self._delete_aa_policy(
|
||||
self.clc,
|
||||
self.module,
|
||||
acct_alias,
|
||||
server.id)
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
@staticmethod
|
||||
def _modify_aa_policy(clc, module, acct_alias, server_id, aa_policy_id):
|
||||
"""
|
||||
modifies the anti affinity policy of the CLC server
|
||||
:param clc: the clc-sdk instance to use
|
||||
:param module: the AnsibleModule object
|
||||
:param acct_alias: the CLC account alias
|
||||
:param server_id: the CLC server id
|
||||
:param aa_policy_id: the anti affinity policy id
|
||||
:return: result: The result from the CLC API call
|
||||
"""
|
||||
result = None
|
||||
if not module.check_mode:
|
||||
try:
|
||||
result = clc.v2.API.Call('PUT',
|
||||
'servers/%s/%s/antiAffinityPolicy' % (
|
||||
acct_alias,
|
||||
server_id),
|
||||
json.dumps({"id": aa_policy_id}))
|
||||
except APIFailedResponse as ex:
|
||||
module.fail_json(
|
||||
msg='Unable to modify anti affinity policy to server : "{0}". {1}'.format(
|
||||
server_id, str(ex.response_text)))
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _delete_aa_policy(clc, module, acct_alias, server_id):
|
||||
"""
|
||||
Delete the anti affinity policy of the CLC server
|
||||
:param clc: the clc-sdk instance to use
|
||||
:param module: the AnsibleModule object
|
||||
:param acct_alias: the CLC account alias
|
||||
:param server_id: the CLC server id
|
||||
:return: result: The result from the CLC API call
|
||||
"""
|
||||
result = None
|
||||
if not module.check_mode:
|
||||
try:
|
||||
result = clc.v2.API.Call('DELETE',
|
||||
'servers/%s/%s/antiAffinityPolicy' % (
|
||||
acct_alias,
|
||||
server_id),
|
||||
json.dumps({}))
|
||||
except APIFailedResponse as ex:
|
||||
module.fail_json(
|
||||
msg='Unable to delete anti affinity policy to server : "{0}". {1}'.format(
|
||||
server_id, str(ex.response_text)))
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _get_aa_policy_id_by_name(clc, module, alias, aa_policy_name):
|
||||
"""
|
||||
retrieves the anti affinity policy id of the server based on the name of the policy
|
||||
:param clc: the clc-sdk instance to use
|
||||
:param module: the AnsibleModule object
|
||||
:param alias: the CLC account alias
|
||||
:param aa_policy_name: the anti affinity policy name
|
||||
:return: aa_policy_id: The anti affinity policy id
|
||||
"""
|
||||
aa_policy_id = None
|
||||
try:
|
||||
aa_policies = clc.v2.API.Call(method='GET',
|
||||
url='antiAffinityPolicies/%s' % alias)
|
||||
except APIFailedResponse as ex:
|
||||
return module.fail_json(
|
||||
msg='Unable to fetch anti affinity policies from account alias : "{0}". {1}'.format(
|
||||
alias, str(ex.response_text)))
|
||||
for aa_policy in aa_policies.get('items'):
|
||||
if aa_policy.get('name') == aa_policy_name:
|
||||
if not aa_policy_id:
|
||||
aa_policy_id = aa_policy.get('id')
|
||||
else:
|
||||
return module.fail_json(
|
||||
msg='multiple anti affinity policies were found with policy name : %s' % aa_policy_name)
|
||||
if not aa_policy_id:
|
||||
module.fail_json(
|
||||
msg='No anti affinity policy was found with policy name : %s' % aa_policy_name)
|
||||
return aa_policy_id
|
||||
|
||||
@staticmethod
|
||||
def _get_aa_policy_id_of_server(clc, module, alias, server_id):
|
||||
"""
|
||||
retrieves the anti affinity policy id of the server based on the CLC server id
|
||||
:param clc: the clc-sdk instance to use
|
||||
:param module: the AnsibleModule object
|
||||
:param alias: the CLC account alias
|
||||
:param server_id: the CLC server id
|
||||
:return: aa_policy_id: The anti affinity policy id
|
||||
"""
|
||||
aa_policy_id = None
|
||||
try:
|
||||
result = clc.v2.API.Call(
|
||||
method='GET', url='servers/%s/%s/antiAffinityPolicy' %
|
||||
(alias, server_id))
|
||||
aa_policy_id = result.get('id')
|
||||
except APIFailedResponse as ex:
|
||||
if ex.response_status_code != 404:
|
||||
module.fail_json(msg='Unable to fetch anti affinity policy for server "{0}". {1}'.format(
|
||||
server_id, str(ex.response_text)))
|
||||
return aa_policy_id
|
||||
|
||||
def _ensure_alert_policy_present(
|
||||
self, server, server_params):
|
||||
"""
|
||||
ensures the server is updated with the provided alert policy
|
||||
:param server: the CLC server object
|
||||
:param server_params: the dictionary of server parameters
|
||||
:return: (changed, group) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
"""
|
||||
changed = False
|
||||
acct_alias = self.clc.v2.Account.GetAlias()
|
||||
alert_policy_id = server_params.get('alert_policy_id')
|
||||
alert_policy_name = server_params.get('alert_policy_name')
|
||||
if not alert_policy_id and alert_policy_name:
|
||||
alert_policy_id = self._get_alert_policy_id_by_name(
|
||||
self.clc,
|
||||
self.module,
|
||||
acct_alias,
|
||||
alert_policy_name)
|
||||
if alert_policy_id and not self._alert_policy_exists(
|
||||
server, alert_policy_id):
|
||||
self._add_alert_policy_to_server(
|
||||
self.clc,
|
||||
self.module,
|
||||
acct_alias,
|
||||
server.id,
|
||||
alert_policy_id)
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
def _ensure_alert_policy_absent(
|
||||
self, server, server_params):
|
||||
"""
|
||||
ensures the alert policy is removed from the server
|
||||
:param server: the CLC server object
|
||||
:param server_params: the dictionary of server parameters
|
||||
:return: (changed, group) -
|
||||
changed: Boolean whether a change was made
|
||||
result: The result from the CLC API call
|
||||
"""
|
||||
changed = False
|
||||
|
||||
acct_alias = self.clc.v2.Account.GetAlias()
|
||||
alert_policy_id = server_params.get('alert_policy_id')
|
||||
alert_policy_name = server_params.get('alert_policy_name')
|
||||
if not alert_policy_id and alert_policy_name:
|
||||
alert_policy_id = self._get_alert_policy_id_by_name(
|
||||
self.clc,
|
||||
self.module,
|
||||
acct_alias,
|
||||
alert_policy_name)
|
||||
|
||||
if alert_policy_id and self._alert_policy_exists(
|
||||
server, alert_policy_id):
|
||||
self._remove_alert_policy_to_server(
|
||||
self.clc,
|
||||
self.module,
|
||||
acct_alias,
|
||||
server.id,
|
||||
alert_policy_id)
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
@staticmethod
|
||||
def _add_alert_policy_to_server(
|
||||
clc, module, acct_alias, server_id, alert_policy_id):
|
||||
"""
|
||||
add the alert policy to CLC server
|
||||
:param clc: the clc-sdk instance to use
|
||||
:param module: the AnsibleModule object
|
||||
:param acct_alias: the CLC account alias
|
||||
:param server_id: the CLC server id
|
||||
:param alert_policy_id: the alert policy id
|
||||
:return: result: The result from the CLC API call
|
||||
"""
|
||||
result = None
|
||||
if not module.check_mode:
|
||||
try:
|
||||
result = clc.v2.API.Call('POST',
|
||||
'servers/%s/%s/alertPolicies' % (
|
||||
acct_alias,
|
||||
server_id),
|
||||
json.dumps({"id": alert_policy_id}))
|
||||
except APIFailedResponse as ex:
|
||||
module.fail_json(msg='Unable to set alert policy to the server : "{0}". {1}'.format(
|
||||
server_id, str(ex.response_text)))
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _remove_alert_policy_to_server(
|
||||
clc, module, acct_alias, server_id, alert_policy_id):
|
||||
"""
|
||||
remove the alert policy to the CLC server
|
||||
:param clc: the clc-sdk instance to use
|
||||
:param module: the AnsibleModule object
|
||||
:param acct_alias: the CLC account alias
|
||||
:param server_id: the CLC server id
|
||||
:param alert_policy_id: the alert policy id
|
||||
:return: result: The result from the CLC API call
|
||||
"""
|
||||
result = None
|
||||
if not module.check_mode:
|
||||
try:
|
||||
result = clc.v2.API.Call('DELETE',
|
||||
'servers/%s/%s/alertPolicies/%s'
|
||||
% (acct_alias, server_id, alert_policy_id))
|
||||
except APIFailedResponse as ex:
|
||||
module.fail_json(msg='Unable to remove alert policy from the server : "{0}". {1}'.format(
|
||||
server_id, str(ex.response_text)))
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _get_alert_policy_id_by_name(clc, module, alias, alert_policy_name):
|
||||
"""
|
||||
retrieves the alert policy id of the server based on the name of the policy
|
||||
:param clc: the clc-sdk instance to use
|
||||
:param module: the AnsibleModule object
|
||||
:param alias: the CLC account alias
|
||||
:param alert_policy_name: the alert policy name
|
||||
:return: alert_policy_id: The alert policy id
|
||||
"""
|
||||
alert_policy_id = None
|
||||
try:
|
||||
alert_policies = clc.v2.API.Call(method='GET',
|
||||
url='alertPolicies/%s' % alias)
|
||||
except APIFailedResponse as ex:
|
||||
return module.fail_json(msg='Unable to fetch alert policies for account : "{0}". {1}'.format(
|
||||
alias, str(ex.response_text)))
|
||||
for alert_policy in alert_policies.get('items'):
|
||||
if alert_policy.get('name') == alert_policy_name:
|
||||
if not alert_policy_id:
|
||||
alert_policy_id = alert_policy.get('id')
|
||||
else:
|
||||
return module.fail_json(
|
||||
msg='multiple alert policies were found with policy name : %s' % alert_policy_name)
|
||||
return alert_policy_id
|
||||
|
||||
@staticmethod
|
||||
def _alert_policy_exists(server, alert_policy_id):
|
||||
"""
|
||||
Checks if the alert policy exists for the server
|
||||
:param server: the clc server object
|
||||
:param alert_policy_id: the alert policy
|
||||
:return: True: if the given alert policy id associated to the server, False otherwise
|
||||
"""
|
||||
result = False
|
||||
alert_policies = server.alertPolicies
|
||||
if alert_policies:
|
||||
for alert_policy in alert_policies:
|
||||
if alert_policy.get('id') == alert_policy_id:
|
||||
result = True
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _set_user_agent(clc):
|
||||
if hasattr(clc, 'SetRequestsSession'):
|
||||
agent_string = "ClcAnsibleModule/" + __version__
|
||||
ses = requests.Session()
|
||||
ses.headers.update({"Api-Client": agent_string})
|
||||
ses.headers['User-Agent'] += " " + agent_string
|
||||
clc.SetRequestsSession(ses)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
The main function. Instantiates the module and calls process_request.
|
||||
:return: none
|
||||
"""
|
||||
|
||||
argument_dict = ClcModifyServer._define_module_argument_spec()
|
||||
module = AnsibleModule(supports_check_mode=True, **argument_dict)
|
||||
clc_modify_server = ClcModifyServer(module)
|
||||
clc_modify_server.process_request()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
359
plugins/modules/clc_publicip.py
Normal file
359
plugins/modules/clc_publicip.py
Normal file
@@ -0,0 +1,359 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2015 CenturyLink
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: clc_publicip
|
||||
short_description: Add and Delete public IPs on servers in CenturyLink Cloud
|
||||
description:
|
||||
- An Ansible module to add or delete public IP addresses on an existing server or servers in CenturyLink Cloud.
|
||||
deprecated:
|
||||
removed_in: 11.0.0
|
||||
why: >
|
||||
Lumen Public Cloud (formerly known as CenturyLink Cloud) has gone End-of-Life in September 2023.
|
||||
See more at U(https://www.ctl.io/knowledge-base/release-notes/2023/lumen-public-cloud-platform-end-of-life-notice/?).
|
||||
alternative: There is none.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
- community.general.clc
|
||||
author:
|
||||
- "CLC Runner (@clc-runner)"
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
options:
|
||||
protocol:
|
||||
description:
|
||||
- The protocol that the public IP will listen for.
|
||||
type: str
|
||||
default: TCP
|
||||
choices: ['TCP', 'UDP', 'ICMP']
|
||||
ports:
|
||||
description:
|
||||
- A list of ports to expose. This is required when O(state=present).
|
||||
type: list
|
||||
elements: int
|
||||
server_ids:
|
||||
description:
|
||||
- A list of servers to create public IPs on.
|
||||
type: list
|
||||
required: true
|
||||
elements: str
|
||||
state:
|
||||
description:
|
||||
- Determine whether to create or delete public IPs. If V(present) module will not create a second public IP if one already
|
||||
exists.
|
||||
type: str
|
||||
default: present
|
||||
choices: ['present', 'absent']
|
||||
wait:
|
||||
description:
|
||||
- Whether to wait for the tasks to finish before returning.
|
||||
type: bool
|
||||
default: true
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
# Note - You must set the CLC_V2_API_USERNAME And CLC_V2_API_PASSWD Environment variables before running these examples
|
||||
|
||||
- name: Add Public IP to Server
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Create Public IP For Servers
|
||||
community.general.clc_publicip:
|
||||
protocol: TCP
|
||||
ports:
|
||||
- 80
|
||||
server_ids:
|
||||
- UC1TEST-SVR01
|
||||
- UC1TEST-SVR02
|
||||
state: present
|
||||
register: clc
|
||||
|
||||
- name: Debug
|
||||
ansible.builtin.debug:
|
||||
var: clc
|
||||
|
||||
- name: Delete Public IP from Server
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
connection: local
|
||||
tasks:
|
||||
- name: Create Public IP For Servers
|
||||
community.general.clc_publicip:
|
||||
server_ids:
|
||||
- UC1TEST-SVR01
|
||||
- UC1TEST-SVR02
|
||||
state: absent
|
||||
register: clc
|
||||
|
||||
- name: Debug
|
||||
ansible.builtin.debug:
|
||||
var: clc
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
server_ids:
|
||||
description: The list of server IDs that are changed.
|
||||
returned: success
|
||||
type: list
|
||||
sample: ["UC1TEST-SVR01", "UC1TEST-SVR02"]
|
||||
"""
|
||||
|
||||
__version__ = '${version}'
|
||||
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
REQUESTS_IMP_ERR = None
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
REQUESTS_IMP_ERR = traceback.format_exc()
|
||||
REQUESTS_FOUND = False
|
||||
else:
|
||||
REQUESTS_FOUND = True
|
||||
|
||||
#
|
||||
# Requires the clc-python-sdk.
|
||||
# sudo pip install clc-sdk
|
||||
#
|
||||
CLC_IMP_ERR = None
|
||||
try:
|
||||
import clc as clc_sdk
|
||||
from clc import CLCException
|
||||
except ImportError:
|
||||
CLC_IMP_ERR = traceback.format_exc()
|
||||
CLC_FOUND = False
|
||||
clc_sdk = None
|
||||
else:
|
||||
CLC_FOUND = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
|
||||
class ClcPublicIp(object):
|
||||
clc = clc_sdk
|
||||
module = None
|
||||
|
||||
def __init__(self, module):
|
||||
"""
|
||||
Construct module
|
||||
"""
|
||||
self.module = module
|
||||
if not CLC_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR)
|
||||
if not REQUESTS_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR)
|
||||
if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'):
|
||||
self.module.fail_json(
|
||||
msg='requests library version should be >= 2.5.0')
|
||||
|
||||
self._set_user_agent(self.clc)
|
||||
|
||||
def process_request(self):
|
||||
"""
|
||||
Process the request - Main Code Path
|
||||
:return: Returns with either an exit_json or fail_json
|
||||
"""
|
||||
self._set_clc_credentials_from_env()
|
||||
params = self.module.params
|
||||
server_ids = params['server_ids']
|
||||
ports = params['ports']
|
||||
protocol = params['protocol']
|
||||
state = params['state']
|
||||
|
||||
if state == 'present':
|
||||
changed, changed_server_ids, requests = self.ensure_public_ip_present(
|
||||
server_ids=server_ids, protocol=protocol, ports=ports)
|
||||
elif state == 'absent':
|
||||
changed, changed_server_ids, requests = self.ensure_public_ip_absent(
|
||||
server_ids=server_ids)
|
||||
else:
|
||||
return self.module.fail_json(msg="Unknown State: " + state)
|
||||
self._wait_for_requests_to_complete(requests)
|
||||
return self.module.exit_json(changed=changed,
|
||||
server_ids=changed_server_ids)
|
||||
|
||||
@staticmethod
|
||||
def _define_module_argument_spec():
|
||||
"""
|
||||
Define the argument spec for the ansible module
|
||||
:return: argument spec dictionary
|
||||
"""
|
||||
argument_spec = dict(
|
||||
server_ids=dict(type='list', required=True, elements='str'),
|
||||
protocol=dict(default='TCP', choices=['TCP', 'UDP', 'ICMP']),
|
||||
ports=dict(type='list', elements='int'),
|
||||
wait=dict(type='bool', default=True),
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
)
|
||||
return argument_spec
|
||||
|
||||
def ensure_public_ip_present(self, server_ids, protocol, ports):
|
||||
"""
|
||||
Ensures the given server ids having the public ip available
|
||||
:param server_ids: the list of server ids
|
||||
:param protocol: the ip protocol
|
||||
:param ports: the list of ports to expose
|
||||
:return: (changed, changed_server_ids, results)
|
||||
changed: A flag indicating if there is any change
|
||||
changed_server_ids : the list of server ids that are changed
|
||||
results: The result list from clc public ip call
|
||||
"""
|
||||
changed = False
|
||||
results = []
|
||||
changed_server_ids = []
|
||||
servers = self._get_servers_from_clc(
|
||||
server_ids,
|
||||
'Failed to obtain server list from the CLC API')
|
||||
servers_to_change = [
|
||||
server for server in servers if len(
|
||||
server.PublicIPs().public_ips) == 0]
|
||||
ports_to_expose = [{'protocol': protocol, 'port': port}
|
||||
for port in ports]
|
||||
for server in servers_to_change:
|
||||
if not self.module.check_mode:
|
||||
result = self._add_publicip_to_server(server, ports_to_expose)
|
||||
results.append(result)
|
||||
changed_server_ids.append(server.id)
|
||||
changed = True
|
||||
return changed, changed_server_ids, results
|
||||
|
||||
def _add_publicip_to_server(self, server, ports_to_expose):
|
||||
result = None
|
||||
try:
|
||||
result = server.PublicIPs().Add(ports_to_expose)
|
||||
except CLCException as ex:
|
||||
self.module.fail_json(msg='Failed to add public ip to the server : {0}. {1}'.format(
|
||||
server.id, ex.response_text
|
||||
))
|
||||
return result
|
||||
|
||||
def ensure_public_ip_absent(self, server_ids):
|
||||
"""
|
||||
Ensures the given server ids having the public ip removed if there is any
|
||||
:param server_ids: the list of server ids
|
||||
:return: (changed, changed_server_ids, results)
|
||||
changed: A flag indicating if there is any change
|
||||
changed_server_ids : the list of server ids that are changed
|
||||
results: The result list from clc public ip call
|
||||
"""
|
||||
changed = False
|
||||
results = []
|
||||
changed_server_ids = []
|
||||
servers = self._get_servers_from_clc(
|
||||
server_ids,
|
||||
'Failed to obtain server list from the CLC API')
|
||||
servers_to_change = [
|
||||
server for server in servers if len(
|
||||
server.PublicIPs().public_ips) > 0]
|
||||
for server in servers_to_change:
|
||||
if not self.module.check_mode:
|
||||
result = self._remove_publicip_from_server(server)
|
||||
results.append(result)
|
||||
changed_server_ids.append(server.id)
|
||||
changed = True
|
||||
return changed, changed_server_ids, results
|
||||
|
||||
def _remove_publicip_from_server(self, server):
|
||||
result = None
|
||||
try:
|
||||
for ip_address in server.PublicIPs().public_ips:
|
||||
result = ip_address.Delete()
|
||||
except CLCException as ex:
|
||||
self.module.fail_json(msg='Failed to remove public ip from the server : {0}. {1}'.format(
|
||||
server.id, ex.response_text
|
||||
))
|
||||
return result
|
||||
|
||||
def _wait_for_requests_to_complete(self, requests_lst):
|
||||
"""
|
||||
Waits until the CLC requests are complete if the wait argument is True
|
||||
:param requests_lst: The list of CLC request objects
|
||||
:return: none
|
||||
"""
|
||||
if not self.module.params['wait']:
|
||||
return
|
||||
for request in requests_lst:
|
||||
request.WaitUntilComplete()
|
||||
for request_details in request.requests:
|
||||
if request_details.Status() != 'succeeded':
|
||||
self.module.fail_json(
|
||||
msg='Unable to process public ip request')
|
||||
|
||||
def _set_clc_credentials_from_env(self):
|
||||
"""
|
||||
Set the CLC Credentials on the sdk by reading environment variables
|
||||
:return: none
|
||||
"""
|
||||
env = os.environ
|
||||
v2_api_token = env.get('CLC_V2_API_TOKEN', False)
|
||||
v2_api_username = env.get('CLC_V2_API_USERNAME', False)
|
||||
v2_api_passwd = env.get('CLC_V2_API_PASSWD', False)
|
||||
clc_alias = env.get('CLC_ACCT_ALIAS', False)
|
||||
api_url = env.get('CLC_V2_API_URL', False)
|
||||
|
||||
if api_url:
|
||||
self.clc.defaults.ENDPOINT_URL_V2 = api_url
|
||||
|
||||
if v2_api_token and clc_alias:
|
||||
self.clc._LOGIN_TOKEN_V2 = v2_api_token
|
||||
self.clc._V2_ENABLED = True
|
||||
self.clc.ALIAS = clc_alias
|
||||
elif v2_api_username and v2_api_passwd:
|
||||
self.clc.v2.SetCredentials(
|
||||
api_username=v2_api_username,
|
||||
api_passwd=v2_api_passwd)
|
||||
else:
|
||||
return self.module.fail_json(
|
||||
msg="You must set the CLC_V2_API_USERNAME and CLC_V2_API_PASSWD "
|
||||
"environment variables")
|
||||
|
||||
def _get_servers_from_clc(self, server_ids, message):
|
||||
"""
|
||||
Gets list of servers form CLC api
|
||||
"""
|
||||
try:
|
||||
return self.clc.v2.Servers(server_ids).servers
|
||||
except CLCException as exception:
|
||||
self.module.fail_json(msg=message + ': %s' % exception)
|
||||
|
||||
@staticmethod
|
||||
def _set_user_agent(clc):
|
||||
if hasattr(clc, 'SetRequestsSession'):
|
||||
agent_string = "ClcAnsibleModule/" + __version__
|
||||
ses = requests.Session()
|
||||
ses.headers.update({"Api-Client": agent_string})
|
||||
ses.headers['User-Agent'] += " " + agent_string
|
||||
clc.SetRequestsSession(ses)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
The main function. Instantiates the module and calls process_request.
|
||||
:return: none
|
||||
"""
|
||||
module = AnsibleModule(
|
||||
argument_spec=ClcPublicIp._define_module_argument_spec(),
|
||||
supports_check_mode=True
|
||||
)
|
||||
clc_public_ip = ClcPublicIp(module)
|
||||
clc_public_ip.process_request()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
1554
plugins/modules/clc_server.py
Normal file
1554
plugins/modules/clc_server.py
Normal file
File diff suppressed because it is too large
Load Diff
409
plugins/modules/clc_server_snapshot.py
Normal file
409
plugins/modules/clc_server_snapshot.py
Normal file
@@ -0,0 +1,409 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2015 CenturyLink
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: clc_server_snapshot
|
||||
short_description: Create, Delete and Restore server snapshots in CenturyLink Cloud
|
||||
description:
|
||||
- An Ansible module to Create, Delete and Restore server snapshots in CenturyLink Cloud.
|
||||
deprecated:
|
||||
removed_in: 11.0.0
|
||||
why: >
|
||||
Lumen Public Cloud (formerly known as CenturyLink Cloud) has gone End-of-Life in September 2023.
|
||||
See more at U(https://www.ctl.io/knowledge-base/release-notes/2023/lumen-public-cloud-platform-end-of-life-notice/?).
|
||||
alternative: There is none.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
- community.general.clc
|
||||
author:
|
||||
- "CLC Runner (@clc-runner)"
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
options:
|
||||
server_ids:
|
||||
description:
|
||||
- The list of CLC server IDs.
|
||||
type: list
|
||||
required: true
|
||||
elements: str
|
||||
expiration_days:
|
||||
description:
|
||||
- The number of days to keep the server snapshot before it expires.
|
||||
type: int
|
||||
default: 7
|
||||
required: false
|
||||
state:
|
||||
description:
|
||||
- The state to insure that the provided resources are in.
|
||||
type: str
|
||||
default: 'present'
|
||||
required: false
|
||||
choices: ['present', 'absent', 'restore']
|
||||
wait:
|
||||
description:
|
||||
- Whether to wait for the provisioning tasks to finish before returning.
|
||||
default: 'True'
|
||||
required: false
|
||||
type: str
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
# Note - You must set the CLC_V2_API_USERNAME And CLC_V2_API_PASSWD Environment variables before running these examples
|
||||
|
||||
- name: Create server snapshot
|
||||
community.general.clc_server_snapshot:
|
||||
server_ids:
|
||||
- UC1TEST-SVR01
|
||||
- UC1TEST-SVR02
|
||||
expiration_days: 10
|
||||
wait: true
|
||||
state: present
|
||||
|
||||
- name: Restore server snapshot
|
||||
community.general.clc_server_snapshot:
|
||||
server_ids:
|
||||
- UC1TEST-SVR01
|
||||
- UC1TEST-SVR02
|
||||
wait: true
|
||||
state: restore
|
||||
|
||||
- name: Delete server snapshot
|
||||
community.general.clc_server_snapshot:
|
||||
server_ids:
|
||||
- UC1TEST-SVR01
|
||||
- UC1TEST-SVR02
|
||||
wait: true
|
||||
state: absent
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
server_ids:
|
||||
description: The list of server IDs that are changed.
|
||||
returned: success
|
||||
type: list
|
||||
sample: ["UC1TEST-SVR01", "UC1TEST-SVR02"]
|
||||
"""
|
||||
|
||||
__version__ = '${version}'
|
||||
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
REQUESTS_IMP_ERR = None
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
REQUESTS_IMP_ERR = traceback.format_exc()
|
||||
REQUESTS_FOUND = False
|
||||
else:
|
||||
REQUESTS_FOUND = True
|
||||
|
||||
#
|
||||
# Requires the clc-python-sdk.
|
||||
# sudo pip install clc-sdk
|
||||
#
|
||||
CLC_IMP_ERR = None
|
||||
try:
|
||||
import clc as clc_sdk
|
||||
from clc import CLCException
|
||||
except ImportError:
|
||||
CLC_IMP_ERR = traceback.format_exc()
|
||||
CLC_FOUND = False
|
||||
clc_sdk = None
|
||||
else:
|
||||
CLC_FOUND = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
|
||||
class ClcSnapshot:
|
||||
|
||||
clc = clc_sdk
|
||||
module = None
|
||||
|
||||
def __init__(self, module):
|
||||
"""
|
||||
Construct module
|
||||
"""
|
||||
self.module = module
|
||||
|
||||
if not CLC_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR)
|
||||
if not REQUESTS_FOUND:
|
||||
self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR)
|
||||
if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'):
|
||||
self.module.fail_json(
|
||||
msg='requests library version should be >= 2.5.0')
|
||||
|
||||
self._set_user_agent(self.clc)
|
||||
|
||||
def process_request(self):
|
||||
"""
|
||||
Process the request - Main Code Path
|
||||
:return: Returns with either an exit_json or fail_json
|
||||
"""
|
||||
p = self.module.params
|
||||
server_ids = p['server_ids']
|
||||
expiration_days = p['expiration_days']
|
||||
state = p['state']
|
||||
request_list = []
|
||||
changed = False
|
||||
changed_servers = []
|
||||
|
||||
self._set_clc_credentials_from_env()
|
||||
if state == 'present':
|
||||
changed, request_list, changed_servers = self.ensure_server_snapshot_present(
|
||||
server_ids=server_ids,
|
||||
expiration_days=expiration_days)
|
||||
elif state == 'absent':
|
||||
changed, request_list, changed_servers = self.ensure_server_snapshot_absent(
|
||||
server_ids=server_ids)
|
||||
elif state == 'restore':
|
||||
changed, request_list, changed_servers = self.ensure_server_snapshot_restore(
|
||||
server_ids=server_ids)
|
||||
|
||||
self._wait_for_requests_to_complete(request_list)
|
||||
return self.module.exit_json(
|
||||
changed=changed,
|
||||
server_ids=changed_servers)
|
||||
|
||||
def ensure_server_snapshot_present(self, server_ids, expiration_days):
|
||||
"""
|
||||
Ensures the given set of server_ids have the snapshots created
|
||||
:param server_ids: The list of server_ids to create the snapshot
|
||||
:param expiration_days: The number of days to keep the snapshot
|
||||
:return: (changed, request_list, changed_servers)
|
||||
changed: A flag indicating whether any change was made
|
||||
request_list: the list of clc request objects from CLC API call
|
||||
changed_servers: The list of servers ids that are modified
|
||||
"""
|
||||
request_list = []
|
||||
changed = False
|
||||
servers = self._get_servers_from_clc(
|
||||
server_ids,
|
||||
'Failed to obtain server list from the CLC API')
|
||||
servers_to_change = [
|
||||
server for server in servers if len(
|
||||
server.GetSnapshots()) == 0]
|
||||
for server in servers_to_change:
|
||||
changed = True
|
||||
if not self.module.check_mode:
|
||||
request = self._create_server_snapshot(server, expiration_days)
|
||||
request_list.append(request)
|
||||
changed_servers = [
|
||||
server.id for server in servers_to_change if server.id]
|
||||
return changed, request_list, changed_servers
|
||||
|
||||
def _create_server_snapshot(self, server, expiration_days):
|
||||
"""
|
||||
Create the snapshot for the CLC server
|
||||
:param server: the CLC server object
|
||||
:param expiration_days: The number of days to keep the snapshot
|
||||
:return: the create request object from CLC API Call
|
||||
"""
|
||||
result = None
|
||||
try:
|
||||
result = server.CreateSnapshot(
|
||||
delete_existing=True,
|
||||
expiration_days=expiration_days)
|
||||
except CLCException as ex:
|
||||
self.module.fail_json(msg='Failed to create snapshot for server : {0}. {1}'.format(
|
||||
server.id, ex.response_text
|
||||
))
|
||||
return result
|
||||
|
||||
def ensure_server_snapshot_absent(self, server_ids):
|
||||
"""
|
||||
Ensures the given set of server_ids have the snapshots removed
|
||||
:param server_ids: The list of server_ids to delete the snapshot
|
||||
:return: (changed, request_list, changed_servers)
|
||||
changed: A flag indicating whether any change was made
|
||||
request_list: the list of clc request objects from CLC API call
|
||||
changed_servers: The list of servers ids that are modified
|
||||
"""
|
||||
request_list = []
|
||||
changed = False
|
||||
servers = self._get_servers_from_clc(
|
||||
server_ids,
|
||||
'Failed to obtain server list from the CLC API')
|
||||
servers_to_change = [
|
||||
server for server in servers if len(
|
||||
server.GetSnapshots()) > 0]
|
||||
for server in servers_to_change:
|
||||
changed = True
|
||||
if not self.module.check_mode:
|
||||
request = self._delete_server_snapshot(server)
|
||||
request_list.append(request)
|
||||
changed_servers = [
|
||||
server.id for server in servers_to_change if server.id]
|
||||
return changed, request_list, changed_servers
|
||||
|
||||
def _delete_server_snapshot(self, server):
|
||||
"""
|
||||
Delete snapshot for the CLC server
|
||||
:param server: the CLC server object
|
||||
:return: the delete snapshot request object from CLC API
|
||||
"""
|
||||
result = None
|
||||
try:
|
||||
result = server.DeleteSnapshot()
|
||||
except CLCException as ex:
|
||||
self.module.fail_json(msg='Failed to delete snapshot for server : {0}. {1}'.format(
|
||||
server.id, ex.response_text
|
||||
))
|
||||
return result
|
||||
|
||||
def ensure_server_snapshot_restore(self, server_ids):
|
||||
"""
|
||||
Ensures the given set of server_ids have the snapshots restored
|
||||
:param server_ids: The list of server_ids to delete the snapshot
|
||||
:return: (changed, request_list, changed_servers)
|
||||
changed: A flag indicating whether any change was made
|
||||
request_list: the list of clc request objects from CLC API call
|
||||
changed_servers: The list of servers ids that are modified
|
||||
"""
|
||||
request_list = []
|
||||
changed = False
|
||||
servers = self._get_servers_from_clc(
|
||||
server_ids,
|
||||
'Failed to obtain server list from the CLC API')
|
||||
servers_to_change = [
|
||||
server for server in servers if len(
|
||||
server.GetSnapshots()) > 0]
|
||||
for server in servers_to_change:
|
||||
changed = True
|
||||
if not self.module.check_mode:
|
||||
request = self._restore_server_snapshot(server)
|
||||
request_list.append(request)
|
||||
changed_servers = [
|
||||
server.id for server in servers_to_change if server.id]
|
||||
return changed, request_list, changed_servers
|
||||
|
||||
def _restore_server_snapshot(self, server):
|
||||
"""
|
||||
Restore snapshot for the CLC server
|
||||
:param server: the CLC server object
|
||||
:return: the restore snapshot request object from CLC API
|
||||
"""
|
||||
result = None
|
||||
try:
|
||||
result = server.RestoreSnapshot()
|
||||
except CLCException as ex:
|
||||
self.module.fail_json(msg='Failed to restore snapshot for server : {0}. {1}'.format(
|
||||
server.id, ex.response_text
|
||||
))
|
||||
return result
|
||||
|
||||
def _wait_for_requests_to_complete(self, requests_lst):
|
||||
"""
|
||||
Waits until the CLC requests are complete if the wait argument is True
|
||||
:param requests_lst: The list of CLC request objects
|
||||
:return: none
|
||||
"""
|
||||
if not self.module.params['wait']:
|
||||
return
|
||||
for request in requests_lst:
|
||||
request.WaitUntilComplete()
|
||||
for request_details in request.requests:
|
||||
if request_details.Status() != 'succeeded':
|
||||
self.module.fail_json(
|
||||
msg='Unable to process server snapshot request')
|
||||
|
||||
@staticmethod
|
||||
def define_argument_spec():
|
||||
"""
|
||||
This function defines the dictionary object required for
|
||||
package module
|
||||
:return: the package dictionary object
|
||||
"""
|
||||
argument_spec = dict(
|
||||
server_ids=dict(type='list', required=True, elements='str'),
|
||||
expiration_days=dict(default=7, type='int'),
|
||||
wait=dict(default=True),
|
||||
state=dict(
|
||||
default='present',
|
||||
choices=[
|
||||
'present',
|
||||
'absent',
|
||||
'restore']),
|
||||
)
|
||||
return argument_spec
|
||||
|
||||
def _get_servers_from_clc(self, server_list, message):
|
||||
"""
|
||||
Internal function to fetch list of CLC server objects from a list of server ids
|
||||
:param server_list: The list of server ids
|
||||
:param message: The error message to throw in case of any error
|
||||
:return the list of CLC server objects
|
||||
"""
|
||||
try:
|
||||
return self.clc.v2.Servers(server_list).servers
|
||||
except CLCException as ex:
|
||||
return self.module.fail_json(msg=message + ': %s' % ex)
|
||||
|
||||
def _set_clc_credentials_from_env(self):
|
||||
"""
|
||||
Set the CLC Credentials on the sdk by reading environment variables
|
||||
:return: none
|
||||
"""
|
||||
env = os.environ
|
||||
v2_api_token = env.get('CLC_V2_API_TOKEN', False)
|
||||
v2_api_username = env.get('CLC_V2_API_USERNAME', False)
|
||||
v2_api_passwd = env.get('CLC_V2_API_PASSWD', False)
|
||||
clc_alias = env.get('CLC_ACCT_ALIAS', False)
|
||||
api_url = env.get('CLC_V2_API_URL', False)
|
||||
|
||||
if api_url:
|
||||
self.clc.defaults.ENDPOINT_URL_V2 = api_url
|
||||
|
||||
if v2_api_token and clc_alias:
|
||||
self.clc._LOGIN_TOKEN_V2 = v2_api_token
|
||||
self.clc._V2_ENABLED = True
|
||||
self.clc.ALIAS = clc_alias
|
||||
elif v2_api_username and v2_api_passwd:
|
||||
self.clc.v2.SetCredentials(
|
||||
api_username=v2_api_username,
|
||||
api_passwd=v2_api_passwd)
|
||||
else:
|
||||
return self.module.fail_json(
|
||||
msg="You must set the CLC_V2_API_USERNAME and CLC_V2_API_PASSWD "
|
||||
"environment variables")
|
||||
|
||||
@staticmethod
|
||||
def _set_user_agent(clc):
|
||||
if hasattr(clc, 'SetRequestsSession'):
|
||||
agent_string = "ClcAnsibleModule/" + __version__
|
||||
ses = requests.Session()
|
||||
ses.headers.update({"Api-Client": agent_string})
|
||||
ses.headers['User-Agent'] += " " + agent_string
|
||||
clc.SetRequestsSession(ses)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main function
|
||||
:return: None
|
||||
"""
|
||||
module = AnsibleModule(
|
||||
argument_spec=ClcSnapshot.define_argument_spec(),
|
||||
supports_check_mode=True
|
||||
)
|
||||
clc_snapshot = ClcSnapshot(module)
|
||||
clc_snapshot.process_request()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -50,38 +50,41 @@ cloud_init_data_facts:
|
||||
description: Facts of result and status.
|
||||
returned: success
|
||||
type: dict
|
||||
sample: '{
|
||||
"status": {
|
||||
sample:
|
||||
{
|
||||
"status": {
|
||||
"v1": {
|
||||
"datasource": "DataSourceCloudStack",
|
||||
"errors": []
|
||||
},
|
||||
"result": {
|
||||
"v1": {
|
||||
"datasource": "DataSourceCloudStack",
|
||||
"init": {
|
||||
"errors": [],
|
||||
"finished": 1522066377.0185432,
|
||||
"start": 1522066375.2648022
|
||||
},
|
||||
"init-local": {
|
||||
"errors": [],
|
||||
"finished": 1522066373.70919,
|
||||
"start": 1522066373.4726632
|
||||
},
|
||||
"modules-config": {
|
||||
"errors": [],
|
||||
"finished": 1522066380.9097016,
|
||||
"start": 1522066379.0011985
|
||||
},
|
||||
"modules-final": {
|
||||
"errors": [],
|
||||
"finished": 1522066383.56594,
|
||||
"start": 1522066382.3449218
|
||||
},
|
||||
"stage": null
|
||||
"datasource": "DataSourceCloudStack",
|
||||
"errors": []
|
||||
}
|
||||
}'
|
||||
},
|
||||
"result": {
|
||||
"v1": {
|
||||
"datasource": "DataSourceCloudStack",
|
||||
"init": {
|
||||
"errors": [],
|
||||
"finished": 1522066377.0185432,
|
||||
"start": 1522066375.2648022
|
||||
},
|
||||
"init-local": {
|
||||
"errors": [],
|
||||
"finished": 1522066373.70919,
|
||||
"start": 1522066373.4726632
|
||||
},
|
||||
"modules-config": {
|
||||
"errors": [],
|
||||
"finished": 1522066380.9097016,
|
||||
"start": 1522066379.0011985
|
||||
},
|
||||
"modules-final": {
|
||||
"errors": [],
|
||||
"finished": 1522066383.56594,
|
||||
"start": 1522066382.3449218
|
||||
},
|
||||
"stage": null
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
@@ -127,7 +127,7 @@ options:
|
||||
description:
|
||||
- Whether the record should be the only one for that record type and record name.
|
||||
- Only use with O(state=present).
|
||||
- This will delete all other records with the same record name and type.
|
||||
- This deletes all other records with the same record name and type.
|
||||
type: bool
|
||||
state:
|
||||
description:
|
||||
@@ -157,6 +157,7 @@ options:
|
||||
- The type of DNS record to create. Required if O(state=present).
|
||||
- Support for V(SPF) has been removed from community.general 9.0.0 since that record type is no longer supported by
|
||||
CloudFlare.
|
||||
- Support for V(PTR) has been added in community.general 11.1.0.
|
||||
type: str
|
||||
choices: [A, AAAA, CNAME, DS, MX, NS, SRV, SSHFP, TLSA, CAA, TXT]
|
||||
value:
|
||||
@@ -369,10 +370,7 @@ record:
|
||||
description: Extra Cloudflare-specific information about the record.
|
||||
returned: success
|
||||
type: dict
|
||||
sample:
|
||||
{
|
||||
"auto_added": false
|
||||
}
|
||||
sample: {"auto_added": false}
|
||||
modified_on:
|
||||
description: Record modification date.
|
||||
returned: success
|
||||
@@ -403,7 +401,7 @@ record:
|
||||
returned: success
|
||||
type: list
|
||||
elements: str
|
||||
sample: ['production', 'app']
|
||||
sample: ["production", "app"]
|
||||
version_added: 10.1.0
|
||||
tags_modified_on:
|
||||
description: When the record tags were last modified. Omitted if there are no tags.
|
||||
|
||||
@@ -42,12 +42,12 @@ options:
|
||||
type: str
|
||||
use_ssl:
|
||||
description:
|
||||
- If V(false), an HTTP connection will be used instead of the default HTTPS connection.
|
||||
- If V(false), an HTTP connection is used instead of the default HTTPS connection.
|
||||
type: bool
|
||||
default: true
|
||||
validate_certs:
|
||||
description:
|
||||
- If V(false), SSL certificates will not be validated.
|
||||
- If V(false), SSL certificates are not validated.
|
||||
- This should only set to V(false) when used on personally controlled sites using self-signed certificates.
|
||||
type: bool
|
||||
default: true
|
||||
|
||||
@@ -42,12 +42,12 @@ options:
|
||||
type: str
|
||||
use_ssl:
|
||||
description:
|
||||
- If V(false), an HTTP connection will be used instead of the default HTTPS connection.
|
||||
- If V(false), an HTTP connection is used instead of the default HTTPS connection.
|
||||
type: bool
|
||||
default: true
|
||||
validate_certs:
|
||||
description:
|
||||
- If V(false), SSL certificates will not be validated.
|
||||
- If V(false), SSL certificates are not validated.
|
||||
- This should only set to V(false) when used on personally controlled sites using self-signed certificates.
|
||||
type: bool
|
||||
default: true
|
||||
|
||||
@@ -17,7 +17,7 @@ author:
|
||||
short_description: Dependency Manager for PHP
|
||||
description:
|
||||
- Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs
|
||||
and it will install them in your project for you.
|
||||
and it installs them in your project for you.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
attributes:
|
||||
@@ -45,7 +45,7 @@ options:
|
||||
type: path
|
||||
description:
|
||||
- Directory of your project (see C(--working-dir)). This is required when the command is not run globally.
|
||||
- Will be ignored if O(global_command=true).
|
||||
- This is ignored if O(global_command=true).
|
||||
global_command:
|
||||
description:
|
||||
- Runs the specified command globally.
|
||||
|
||||
@@ -21,8 +21,8 @@ description:
|
||||
name and ID respectively by appending V(service:) Node level checks require a O(check_name) and optionally a O(check_id).
|
||||
- Currently, there is no complete way to retrieve the script, interval or TTL metadata for a registered check. Without this
|
||||
metadata it is not possible to tell if the data supplied with ansible represents a change to a check. As a result this
|
||||
does not attempt to determine changes and will always report a changed occurred. An API method is planned to supply this
|
||||
metadata so at that stage change management will be added.
|
||||
does not attempt to determine changes and it always reports a changed occurred. An API method is planned to supply this
|
||||
metadata so at that stage change management is to be added.
|
||||
- See U(http://consul.io) for more details.
|
||||
requirements:
|
||||
- python-consul
|
||||
@@ -83,25 +83,25 @@ options:
|
||||
service_address:
|
||||
type: str
|
||||
description:
|
||||
- The address to advertise that the service will be listening on. This value will be passed as the C(address) parameter
|
||||
to Consul's C(/v1/agent/service/register) API method, so refer to the Consul API documentation for further details.
|
||||
- The address to advertise that the service is listening on. This value is passed as the C(address) parameter to Consul's
|
||||
C(/v1/agent/service/register) API method, so refer to the Consul API documentation for further details.
|
||||
tags:
|
||||
type: list
|
||||
elements: str
|
||||
description:
|
||||
- Tags that will be attached to the service registration.
|
||||
- Tags that are attached to the service registration.
|
||||
script:
|
||||
type: str
|
||||
description:
|
||||
- The script/command that will be run periodically to check the health of the service.
|
||||
- The script/command that is run periodically to check the health of the service.
|
||||
- Requires O(interval) to be provided.
|
||||
- Mutually exclusive with O(ttl), O(tcp) and O(http).
|
||||
interval:
|
||||
type: str
|
||||
description:
|
||||
- The interval at which the service check will be run. This is a number with a V(s) or V(m) suffix to signify the units
|
||||
of seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s) will be used by default, for example
|
||||
V(10) will be V(10s).
|
||||
- The interval at which the service check is run. This is a number with a V(s) or V(m) suffix to signify the units of
|
||||
seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s) is used by default, for example V(10)
|
||||
is V(10s).
|
||||
- Required if one of the parameters O(script), O(http), or O(tcp) is specified.
|
||||
check_id:
|
||||
type: str
|
||||
@@ -122,25 +122,25 @@ options:
|
||||
ttl:
|
||||
type: str
|
||||
description:
|
||||
- Checks can be registered with a TTL instead of a O(script) and O(interval) this means that the service will check
|
||||
in with the agent before the TTL expires. If it does not the check will be considered failed. Required if registering
|
||||
a check and the script an interval are missing Similar to the interval this is a number with a V(s) or V(m) suffix
|
||||
to signify the units of seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s) will be used
|
||||
by default, for example V(10) will be V(10s).
|
||||
- Checks can be registered with a TTL instead of a O(script) and O(interval) this means that the service checks in with
|
||||
the agent before the TTL expires. If it does not the check is considered failed. Required if registering a check and
|
||||
the script an interval are missing Similar to the interval this is a number with a V(s) or V(m) suffix to signify
|
||||
the units of seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s) is used by default, for
|
||||
example V(10) is equivalent to V(10s).
|
||||
- Mutually exclusive with O(script), O(tcp) and O(http).
|
||||
tcp:
|
||||
type: str
|
||||
description:
|
||||
- Checks can be registered with a TCP port. This means that Consul will check if the connection attempt to that port
|
||||
is successful (that is, the port is currently accepting connections). The format is V(host:port), for example V(localhost:80).
|
||||
- Checks can be registered with a TCP port. This means that Consul checks if the connection attempt to that port is
|
||||
successful (that is, the port is currently accepting connections). The format is V(host:port), for example V(localhost:80).
|
||||
- Requires O(interval) to be provided.
|
||||
- Mutually exclusive with O(script), O(ttl) and O(http).
|
||||
version_added: '1.3.0'
|
||||
http:
|
||||
type: str
|
||||
description:
|
||||
- Checks can be registered with an HTTP endpoint. This means that Consul will check that the http endpoint returns a
|
||||
successful HTTP status.
|
||||
- Checks can be registered with an HTTP endpoint. This means that Consul checks that the http endpoint returns a successful
|
||||
HTTP status.
|
||||
- Requires O(interval) to be provided.
|
||||
- Mutually exclusive with O(script), O(ttl) and O(tcp).
|
||||
timeout:
|
||||
@@ -148,7 +148,7 @@ options:
|
||||
description:
|
||||
- A custom HTTP check timeout. The Consul default is 10 seconds. Similar to the interval this is a number with a V(s)
|
||||
or V(m) suffix to signify the units of seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s)
|
||||
will be used by default, for example V(10) will be V(10s).
|
||||
is used by default, for example V(10) is equivalent to V(10s).
|
||||
token:
|
||||
type: str
|
||||
description:
|
||||
|
||||
@@ -50,7 +50,7 @@ RETURN = r"""
|
||||
result:
|
||||
description:
|
||||
- The bootstrap result as returned by the Consul HTTP API.
|
||||
- B(Note:) If O(bootstrap_secret) has been specified the C(SecretID) and C(ID) will not contain the secret but C(VALUE_SPECIFIED_IN_NO_LOG_PARAMETER).
|
||||
- B(Note:) If O(bootstrap_secret) has been specified the C(SecretID) and C(ID) do not contain the secret but C(VALUE_SPECIFIED_IN_NO_LOG_PARAMETER).
|
||||
If you pass O(bootstrap_secret), make sure your playbook/role does not depend on this return value!
|
||||
returned: changed
|
||||
type: dict
|
||||
|
||||
@@ -17,9 +17,9 @@ description:
|
||||
- Allows the addition, modification and deletion of checks in a Consul cluster using the agent. For more details on using
|
||||
and configuring Checks, see U(https://developer.hashicorp.com/consul/api-docs/agent/check).
|
||||
- Currently, there is no complete way to retrieve the script, interval or TTL metadata for a registered check. Without this
|
||||
metadata it is not possible to tell if the data supplied with ansible represents a change to a check. As a result this
|
||||
does not attempt to determine changes and will always report a changed occurred. An API method is planned to supply this
|
||||
metadata so at that stage change management will be added.
|
||||
metadata it is not possible to tell if the data supplied with ansible represents a change to a check. As a result, the
|
||||
module does not attempt to determine changes and it always reports a changed occurred. An API method is planned to supply
|
||||
this metadata so at that stage change management is to be added.
|
||||
author:
|
||||
- Michael Ilg (@Ilgmi)
|
||||
extends_documentation_fragment:
|
||||
@@ -36,8 +36,8 @@ attributes:
|
||||
diff_mode:
|
||||
support: partial
|
||||
details:
|
||||
- In check mode the diff will show the object as it is defined in the module options and not the object structure of
|
||||
the Consul API.
|
||||
- In check mode the diff shows the object as it is defined in the module options and not the object structure of the
|
||||
Consul API.
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
@@ -52,13 +52,13 @@ options:
|
||||
id:
|
||||
description:
|
||||
- Specifies a unique ID for this check on the node. This defaults to the O(name) parameter, but it may be necessary
|
||||
to provide an ID for uniqueness. This value will return in the response as "CheckId".
|
||||
to provide an ID for uniqueness. This value is returned in the response as V(CheckId).
|
||||
type: str
|
||||
interval:
|
||||
description:
|
||||
- The interval at which the service check will be run. This is a number with a V(s) or V(m) suffix to signify the units
|
||||
of seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s) will be used by default, for example
|
||||
V(10) will be V(10s).
|
||||
- The interval at which the service check is run. This is a number with a V(s) or V(m) suffix to signify the units of
|
||||
seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s) is used by default, for example V(10)
|
||||
is equivalent to V(10s).
|
||||
- Required if one of the parameters O(args), O(http), or O(tcp) is specified.
|
||||
type: str
|
||||
notes:
|
||||
@@ -74,11 +74,11 @@ options:
|
||||
elements: str
|
||||
ttl:
|
||||
description:
|
||||
- Checks can be registered with a TTL instead of a O(args) and O(interval) this means that the service will check in
|
||||
with the agent before the TTL expires. If it does not the check will be considered failed. Required if registering
|
||||
a check and the script an interval are missing Similar to the interval this is a number with a V(s) or V(m) suffix
|
||||
to signify the units of seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s) will be used
|
||||
by default, for example V(10) will be V(10s).
|
||||
- Checks can be registered with a TTL instead of a O(args) and O(interval) this means that the service checks in with
|
||||
the agent before the TTL expires. If it does not the check is considered failed. Required if registering a check and
|
||||
the script an interval are missing Similar to the interval this is a number with a V(s) or V(m) suffix to signify
|
||||
the units of seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s) is used by default, for
|
||||
example V(10) is equivalent to V(10s).
|
||||
- Mutually exclusive with O(args), O(tcp) and O(http).
|
||||
type: str
|
||||
tcp:
|
||||
@@ -91,8 +91,8 @@ options:
|
||||
version_added: '1.3.0'
|
||||
http:
|
||||
description:
|
||||
- Checks can be registered with an HTTP endpoint. This means that Consul will check that the http endpoint returns a
|
||||
successful HTTP status.
|
||||
- Checks can be registered with an HTTP endpoint. This means that Consul checks that the HTTP endpoint returns a successful
|
||||
HTTP status.
|
||||
- Requires O(interval) to be provided.
|
||||
- Mutually exclusive with O(args), O(ttl) and O(tcp).
|
||||
type: str
|
||||
@@ -100,7 +100,7 @@ options:
|
||||
description:
|
||||
- A custom HTTP check timeout. The Consul default is 10 seconds. Similar to the interval this is a number with a V(s)
|
||||
or V(m) suffix to signify the units of seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s)
|
||||
will be used by default, for example V(10) will be V(10s).
|
||||
is used by default, for example V(10) is equivalent to V(10s).
|
||||
type: str
|
||||
service_id:
|
||||
description:
|
||||
|
||||
@@ -31,7 +31,7 @@ attributes:
|
||||
diff_mode:
|
||||
support: partial
|
||||
details:
|
||||
- In check mode the diff will miss operational attributes.
|
||||
- In check mode the diff misses operational attributes.
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
@@ -50,13 +50,13 @@ options:
|
||||
type: str
|
||||
tags:
|
||||
description:
|
||||
- Tags that will be attached to the service registration.
|
||||
- Tags that are attached to the service registration.
|
||||
type: list
|
||||
elements: str
|
||||
address:
|
||||
description:
|
||||
- The address to advertise that the service will be listening on. This value will be passed as the C(address) parameter
|
||||
to Consul's C(/v1/agent/service/register) API method, so refer to the Consul API documentation for further details.
|
||||
- The address to advertise that the service listens on. This value is passed as the C(address) parameter to Consul's
|
||||
C(/v1/agent/service/register) API method, so refer to the Consul API documentation for further details.
|
||||
type: str
|
||||
meta:
|
||||
description:
|
||||
|
||||
@@ -29,7 +29,7 @@ attributes:
|
||||
diff_mode:
|
||||
support: partial
|
||||
details:
|
||||
- In check mode the diff will miss operational attributes.
|
||||
- In check mode the diff misses operational attributes.
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
@@ -71,7 +71,7 @@ options:
|
||||
config:
|
||||
description:
|
||||
- The raw configuration to use for the chosen auth method.
|
||||
- Contents will vary depending upon the type chosen.
|
||||
- Contents vary depending upon the O(type) chosen.
|
||||
- Required when the auth method is created.
|
||||
type: dict
|
||||
"""
|
||||
|
||||
@@ -29,7 +29,7 @@ attributes:
|
||||
diff_mode:
|
||||
support: partial
|
||||
details:
|
||||
- In check mode the diff will miss operational attributes.
|
||||
- In check mode the diff misses operational attributes.
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
|
||||
@@ -36,12 +36,12 @@ options:
|
||||
state:
|
||||
description:
|
||||
- The action to take with the supplied key and value. If the state is V(present) and O(value) is set, the key contents
|
||||
will be set to the value supplied and C(changed) will be set to V(true) only if the value was different to the current
|
||||
contents. If the state is V(present) and O(value) is not set, the existing value associated to the key will be returned.
|
||||
The state V(absent) will remove the key/value pair, again C(changed) will be set to V(true) only if the key actually
|
||||
existed prior to the removal. An attempt can be made to obtain or free the lock associated with a key/value pair with
|
||||
the states V(acquire) or V(release) respectively. A valid session must be supplied to make the attempt C(changed)
|
||||
will be V(true) if the attempt is successful, V(false) otherwise.
|
||||
is set to the value supplied and C(changed) is set to V(true) only if the value was different to the current contents.
|
||||
If the state is V(present) and O(value) is not set, the existing value associated to the key is returned. The state
|
||||
V(absent) is used to remove the key/value pair, again C(changed) is set to V(true) only if the key actually existed
|
||||
prior to the removal. An attempt can be made to obtain or free the lock associated with a key/value pair with the
|
||||
states V(acquire) or V(release) respectively. A valid session must be supplied to make the attempt C(changed) is V(true)
|
||||
if the attempt is successful, V(false) otherwise.
|
||||
type: str
|
||||
choices: [absent, acquire, present, release]
|
||||
default: present
|
||||
@@ -73,9 +73,8 @@ options:
|
||||
type: str
|
||||
cas:
|
||||
description:
|
||||
- Used when acquiring a lock with a session. If the O(cas) is V(0), then Consul will only put the key if it does not
|
||||
already exist. If the O(cas) value is non-zero, then the key is only set if the index matches the ModifyIndex of that
|
||||
key.
|
||||
- Used when acquiring a lock with a session. If the O(cas) is V(0), then Consul only puts the key if it does not already
|
||||
exist. If the O(cas) value is non-zero, then the key is only set if the index matches the ModifyIndex of that key.
|
||||
type: str
|
||||
flags:
|
||||
description:
|
||||
@@ -103,8 +102,7 @@ options:
|
||||
default: true
|
||||
datacenter:
|
||||
description:
|
||||
- The name of the datacenter to query. If unspecified, the query will default to the datacenter of the Consul agent
|
||||
on O(host).
|
||||
- The name of the datacenter to query. If unspecified, the query defaults to the datacenter of the Consul agent on O(host).
|
||||
type: str
|
||||
version_added: 10.0.0
|
||||
"""
|
||||
|
||||
@@ -31,7 +31,7 @@ attributes:
|
||||
support: partial
|
||||
version_added: 8.3.0
|
||||
details:
|
||||
- In check mode the diff will miss operational attributes.
|
||||
- In check mode the diff misses operational attributes.
|
||||
action_group:
|
||||
version_added: 8.3.0
|
||||
options:
|
||||
|
||||
@@ -29,7 +29,7 @@ attributes:
|
||||
diff_mode:
|
||||
support: partial
|
||||
details:
|
||||
- In check mode the diff will miss operational attributes.
|
||||
- In check mode the diff misses operational attributes.
|
||||
version_added: 8.3.0
|
||||
action_group:
|
||||
version_added: 8.3.0
|
||||
@@ -48,15 +48,15 @@ options:
|
||||
description:
|
||||
description:
|
||||
- Description of the role.
|
||||
- If not specified, the assigned description will not be changed.
|
||||
- If not specified, the assigned description is not changed.
|
||||
type: str
|
||||
policies:
|
||||
type: list
|
||||
elements: dict
|
||||
description:
|
||||
- List of policies to attach to the role. Each policy is a dict.
|
||||
- If the parameter is left blank, any policies currently assigned will not be changed.
|
||||
- Any empty array (V([])) will clear any policies previously set.
|
||||
- If the parameter is left blank, any policies currently assigned are not changed.
|
||||
- Any empty array (V([])) clears any policies previously set.
|
||||
suboptions:
|
||||
name:
|
||||
description:
|
||||
@@ -90,8 +90,8 @@ options:
|
||||
elements: dict
|
||||
description:
|
||||
- List of service identities to attach to the role.
|
||||
- If not specified, any service identities currently assigned will not be changed.
|
||||
- If the parameter is an empty array (V([])), any node identities assigned will be unassigned.
|
||||
- If not specified, any service identities currently assigned are not changed.
|
||||
- If the parameter is an empty array (V([])), any node identities assigned are unassigned.
|
||||
suboptions:
|
||||
service_name:
|
||||
description:
|
||||
@@ -106,9 +106,9 @@ options:
|
||||
- name
|
||||
datacenters:
|
||||
description:
|
||||
- The datacenters the policies will be effective.
|
||||
- This will result in effective policy only being valid in this datacenter.
|
||||
- If an empty array (V([])) is specified, the policies will valid in all datacenters.
|
||||
- The datacenters where the policies are effective.
|
||||
- This results in effective policy only being valid in this datacenter.
|
||||
- If an empty array (V([])) is specified, the policies are valid in all datacenters.
|
||||
- Including those which do not yet exist but may in the future.
|
||||
type: list
|
||||
elements: str
|
||||
@@ -117,8 +117,8 @@ options:
|
||||
elements: dict
|
||||
description:
|
||||
- List of node identities to attach to the role.
|
||||
- If not specified, any node identities currently assigned will not be changed.
|
||||
- If the parameter is an empty array (V([])), any node identities assigned will be unassigned.
|
||||
- If not specified, any node identities currently assigned are not changed.
|
||||
- If the parameter is an empty array (V([])), any node identities assigned are unassigned.
|
||||
suboptions:
|
||||
node_name:
|
||||
description:
|
||||
@@ -134,7 +134,7 @@ options:
|
||||
datacenter:
|
||||
description:
|
||||
- The nodes datacenter.
|
||||
- This will result in effective policy only being valid in this datacenter.
|
||||
- This results in effective policy only being valid in this datacenter.
|
||||
type: str
|
||||
required: true
|
||||
"""
|
||||
|
||||
@@ -57,7 +57,7 @@ options:
|
||||
default: 15
|
||||
node:
|
||||
description:
|
||||
- The name of the node that with which the session will be associated. By default this is the name of the agent.
|
||||
- The name of the node that with which the session is associated. By default this is the name of the agent.
|
||||
type: str
|
||||
datacenter:
|
||||
description:
|
||||
@@ -65,8 +65,8 @@ options:
|
||||
type: str
|
||||
checks:
|
||||
description:
|
||||
- Checks that will be used to verify the session health. If all the checks fail, the session will be invalidated and
|
||||
any locks associated with the session will be release and can be acquired once the associated lock delay has expired.
|
||||
- Checks that are used to verify the session health. If all the checks fail, the session is invalidated and any locks
|
||||
associated with the session are released and can be acquired once the associated lock delay has expired.
|
||||
type: list
|
||||
elements: str
|
||||
behavior:
|
||||
|
||||
@@ -29,7 +29,7 @@ attributes:
|
||||
diff_mode:
|
||||
support: partial
|
||||
details:
|
||||
- In check mode the diff will miss operational attributes.
|
||||
- In check mode the diff misses operational attributes.
|
||||
action_group:
|
||||
version_added: 8.3.0
|
||||
options:
|
||||
@@ -41,11 +41,11 @@ options:
|
||||
type: str
|
||||
accessor_id:
|
||||
description:
|
||||
- Specifies a UUID to use as the token's Accessor ID. If not specified a UUID will be generated for this field.
|
||||
- Specifies a UUID to use as the token's Accessor ID. If not specified a UUID is generated for this field.
|
||||
type: str
|
||||
secret_id:
|
||||
description:
|
||||
- Specifies a UUID to use as the token's Secret ID. If not specified a UUID will be generated for this field.
|
||||
- Specifies a UUID to use as the token's Secret ID. If not specified a UUID is generated for this field.
|
||||
type: str
|
||||
description:
|
||||
description:
|
||||
@@ -56,8 +56,8 @@ options:
|
||||
elements: dict
|
||||
description:
|
||||
- List of policies to attach to the token. Each policy is a dict.
|
||||
- If the parameter is left blank, any policies currently assigned will not be changed.
|
||||
- Any empty array (V([])) will clear any policies previously set.
|
||||
- If the parameter is left blank, any policies currently assigned are not changed.
|
||||
- Any empty array (V([])) clears any policies previously set.
|
||||
suboptions:
|
||||
name:
|
||||
description:
|
||||
@@ -74,8 +74,8 @@ options:
|
||||
elements: dict
|
||||
description:
|
||||
- List of roles to attach to the token. Each role is a dict.
|
||||
- If the parameter is left blank, any roles currently assigned will not be changed.
|
||||
- Any empty array (V([])) will clear any roles previously set.
|
||||
- If the parameter is left blank, any roles currently assigned are not changed.
|
||||
- Any empty array (V([])) clears any roles previously set.
|
||||
suboptions:
|
||||
name:
|
||||
description:
|
||||
@@ -108,8 +108,8 @@ options:
|
||||
elements: dict
|
||||
description:
|
||||
- List of service identities to attach to the token.
|
||||
- If not specified, any service identities currently assigned will not be changed.
|
||||
- If the parameter is an empty array (V([])), any node identities assigned will be unassigned.
|
||||
- If not specified, any service identities currently assigned are not changed.
|
||||
- If the parameter is an empty array (V([])), any node identities assigned are unassigned.
|
||||
suboptions:
|
||||
service_name:
|
||||
description:
|
||||
@@ -120,8 +120,8 @@ options:
|
||||
required: true
|
||||
datacenters:
|
||||
description:
|
||||
- The datacenters the token will be effective.
|
||||
- If an empty array (V([])) is specified, the token will valid in all datacenters.
|
||||
- The datacenters where the token is effective.
|
||||
- If an empty array (V([])) is specified, the token is valid in all datacenters.
|
||||
- Including those which do not yet exist but may in the future.
|
||||
type: list
|
||||
elements: str
|
||||
@@ -130,8 +130,8 @@ options:
|
||||
elements: dict
|
||||
description:
|
||||
- List of node identities to attach to the token.
|
||||
- If not specified, any node identities currently assigned will not be changed.
|
||||
- If the parameter is an empty array (V([])), any node identities assigned will be unassigned.
|
||||
- If not specified, any node identities currently assigned are not changed.
|
||||
- If the parameter is an empty array (V([])), any node identities assigned are unassigned.
|
||||
suboptions:
|
||||
node_name:
|
||||
description:
|
||||
@@ -143,7 +143,7 @@ options:
|
||||
datacenter:
|
||||
description:
|
||||
- The nodes datacenter.
|
||||
- This will result in effective token only being valid in this datacenter.
|
||||
- This results in effective token only being valid in this datacenter.
|
||||
type: str
|
||||
required: true
|
||||
local:
|
||||
@@ -152,7 +152,7 @@ options:
|
||||
type: bool
|
||||
expiration_ttl:
|
||||
description:
|
||||
- This is a convenience field and if set will initialize the C(expiration_time). Can be specified in the form of V(60s)
|
||||
- This is a convenience field and if set it initializes the C(expiration_time). Can be specified in the form of V(60s)
|
||||
or V(5m) (that is, 60 seconds or 5 minutes, respectively). Ingored when the token is updated!
|
||||
type: str
|
||||
"""
|
||||
|
||||
@@ -59,16 +59,18 @@ options:
|
||||
install_recommendations:
|
||||
description:
|
||||
- If V(true), installs dependencies declared as recommends per META spec.
|
||||
- If V(false), it ensures the dependencies declared as recommends are not installed, overriding any decision made earlier in E(PERL_CPANM_OPT).
|
||||
- If parameter is not set, C(cpanm) will use its existing defaults.
|
||||
- If V(false), it ensures the dependencies declared as recommends are not installed, overriding any decision made earlier
|
||||
in E(PERL_CPANM_OPT).
|
||||
- If parameter is not set, C(cpanm) uses its existing defaults.
|
||||
- When these dependencies fail to install, cpanm continues the installation, since they are just recommendation.
|
||||
type: bool
|
||||
version_added: 10.3.0
|
||||
install_suggestions:
|
||||
description:
|
||||
- If V(true), installs dependencies declared as suggests per META spec.
|
||||
- If V(false), it ensures the dependencies declared as suggests are not installed, overriding any decision made earlier in E(PERL_CPANM_OPT).
|
||||
- If parameter is not set, C(cpanm) will use its existing defaults.
|
||||
- If V(false), it ensures the dependencies declared as suggests are not installed, overriding any decision made earlier
|
||||
in E(PERL_CPANM_OPT).
|
||||
- If parameter is not set, C(cpanm) uses its existing defaults.
|
||||
- When these dependencies fail to install, cpanm continues the installation, since they are just suggestion.
|
||||
type: bool
|
||||
version_added: 10.3.0
|
||||
@@ -97,14 +99,13 @@ options:
|
||||
notes:
|
||||
- Please note that U(http://search.cpan.org/dist/App-cpanminus/bin/cpanm, cpanm) must be installed on the remote host.
|
||||
- 'This module now comes with a choice of execution O(mode): V(compatibility) or V(new).'
|
||||
- 'O(mode=compatibility): When using V(compatibility) mode, the module will keep backward compatibility. This was the default
|
||||
- 'O(mode=compatibility): When using V(compatibility) mode, the module keeps backward compatibility. This was the default
|
||||
mode before community.general 9.0.0. O(name) must be either a module name or a distribution file. If the perl module given
|
||||
by O(name) is installed (at the exact O(version) when specified), then nothing happens. Otherwise, it will be installed
|
||||
using the C(cpanm) executable. O(name) cannot be an URL, or a git URL. C(cpanm) version specifiers do not work in this
|
||||
mode.'
|
||||
- 'O(mode=new): When using V(new) mode, the module will behave differently. The O(name) parameter may refer to a module
|
||||
name, a distribution file, a HTTP URL or a git repository URL as described in C(cpanminus) documentation. C(cpanm) version
|
||||
specifiers are recognized. This is the default mode from community.general 9.0.0 onwards.'
|
||||
by O(name) is installed (at the exact O(version) when specified), then nothing happens. Otherwise, it is installed using
|
||||
the C(cpanm) executable. O(name) cannot be an URL, or a git URL. C(cpanm) version specifiers do not work in this mode.'
|
||||
- 'O(mode=new): When using V(new) mode, the module behaves differently. The O(name) parameter may refer to a module name,
|
||||
a distribution file, a HTTP URL or a git repository URL as described in C(cpanminus) documentation. C(cpanm) version specifiers
|
||||
are recognized. This is the default mode from community.general 9.0.0 onwards.'
|
||||
seealso:
|
||||
- name: C(cpanm) command manual page
|
||||
description: Manual page for the command.
|
||||
@@ -204,6 +205,7 @@ class CPANMinus(ModuleHelper):
|
||||
pkg_spec=cmd_runner_fmt.as_list(),
|
||||
cpanm_version=cmd_runner_fmt.as_fixed("--version"),
|
||||
)
|
||||
use_old_vardict = False
|
||||
|
||||
def __init_module__(self):
|
||||
v = self.vars
|
||||
|
||||
@@ -43,12 +43,12 @@ options:
|
||||
type: str
|
||||
insertafter:
|
||||
description:
|
||||
- If specified, the variable will be inserted after the variable specified.
|
||||
- If specified, the variable is inserted after the variable specified.
|
||||
- Used with O(state=present).
|
||||
type: str
|
||||
insertbefore:
|
||||
description:
|
||||
- Used with O(state=present). If specified, the variable will be inserted just before the variable specified.
|
||||
- Used with O(state=present). If specified, the variable is inserted just before the variable specified.
|
||||
type: str
|
||||
state:
|
||||
description:
|
||||
|
||||
@@ -24,14 +24,14 @@ options:
|
||||
name:
|
||||
description:
|
||||
- Name of the encrypted block device as it appears in the C(/etc/crypttab) file, or optionally prefixed with V(/dev/mapper/),
|
||||
as it appears in the filesystem. V(/dev/mapper/) will be stripped from O(name).
|
||||
as it appears in the filesystem. V(/dev/mapper/) is stripped from O(name).
|
||||
type: str
|
||||
required: true
|
||||
state:
|
||||
description:
|
||||
- Use V(present) to add a line to C(/etc/crypttab) or update its definition if already present.
|
||||
- Use V(absent) to remove a line with matching O(name).
|
||||
- Use V(opts_present) to add options to those already present; options with different values will be updated.
|
||||
- Use V(opts_present) to add options to those already present; options with different values are updated.
|
||||
- Use V(opts_absent) to remove options from the existing set.
|
||||
type: str
|
||||
required: true
|
||||
@@ -73,6 +73,14 @@ EXAMPLES = r"""
|
||||
opts: discard
|
||||
loop: '{{ ansible_mounts }}'
|
||||
when: "'/dev/mapper/luks-' in item.device"
|
||||
|
||||
- name: Add entry to /etc/crypttab for luks-home with password file
|
||||
community.general.crypttab:
|
||||
name: luks-home
|
||||
backing_device: UUID=123e4567-e89b-12d3-a456-426614174000
|
||||
password: /root/keys/luks-home.key
|
||||
opts: discard,cipher=aes-cbc-essiv:sha256
|
||||
state: present
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
@@ -16,7 +16,7 @@ __metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: datadog_event
|
||||
short_description: Posts events to Datadog service
|
||||
short_description: Posts events to Datadog service
|
||||
description:
|
||||
- Allows to post events to Datadog (www.datadoghq.com) service.
|
||||
- Uses http://docs.datadoghq.com/api/#events API.
|
||||
@@ -89,8 +89,8 @@ options:
|
||||
- An arbitrary string to use for aggregation.
|
||||
validate_certs:
|
||||
description:
|
||||
- If V(false), SSL certificates will not be validated. This should only be used on personally controlled sites using
|
||||
self-signed certificates.
|
||||
- If V(false), SSL certificates are not validated. This should only be used on personally controlled sites using self-signed
|
||||
certificates.
|
||||
type: bool
|
||||
default: true
|
||||
"""
|
||||
|
||||
@@ -92,26 +92,26 @@ options:
|
||||
type: dict
|
||||
description:
|
||||
- Dictionary of scopes to silence, with timestamps or None.
|
||||
- Each scope will be muted until the given POSIX timestamp or forever if the value is None.
|
||||
- Each scope is muted until the given POSIX timestamp or forever if the value is V(None).
|
||||
notify_no_data:
|
||||
description:
|
||||
- Whether this monitor will notify when data stops reporting.
|
||||
- Whether this monitor notifies when data stops reporting.
|
||||
type: bool
|
||||
default: false
|
||||
no_data_timeframe:
|
||||
description:
|
||||
- The number of minutes before a monitor will notify when data stops reporting.
|
||||
- The number of minutes before a monitor notifies when data stops reporting.
|
||||
- Must be at least 2x the monitor timeframe for metric alerts or 2 minutes for service checks.
|
||||
- If not specified, it defaults to 2x timeframe for metric, 2 minutes for service.
|
||||
type: str
|
||||
timeout_h:
|
||||
description:
|
||||
- The number of hours of the monitor not reporting data before it will automatically resolve from a triggered state.
|
||||
- The number of hours of the monitor not reporting data before it automatically resolves from a triggered state.
|
||||
type: str
|
||||
renotify_interval:
|
||||
description:
|
||||
- The number of minutes after the last notification before a monitor will re-notify on the current status.
|
||||
- It will only re-notify if it is not resolved.
|
||||
- The number of minutes after the last notification before a monitor re-notifies on the current status.
|
||||
- It only re-notifies if it is not resolved.
|
||||
type: str
|
||||
escalation_message:
|
||||
description:
|
||||
@@ -120,7 +120,7 @@ options:
|
||||
type: str
|
||||
notify_audit:
|
||||
description:
|
||||
- Whether tagged users will be notified on changes to this monitor.
|
||||
- Whether tagged users are notified on changes to this monitor.
|
||||
type: bool
|
||||
default: false
|
||||
thresholds:
|
||||
@@ -138,7 +138,7 @@ options:
|
||||
require_full_window:
|
||||
description:
|
||||
- Whether this monitor needs a full window of data before it gets evaluated.
|
||||
- We highly recommend you set this to False for sparse metrics, otherwise some evaluations will be skipped.
|
||||
- We highly recommend you set this to V(false) for sparse metrics, otherwise some evaluations are skipped.
|
||||
type: bool
|
||||
new_host_delay:
|
||||
description:
|
||||
@@ -153,7 +153,7 @@ options:
|
||||
id:
|
||||
description:
|
||||
- The ID of the alert.
|
||||
- If set, will be used instead of the name to locate the alert.
|
||||
- If set, it is used instead of O(name) to locate the alert.
|
||||
type: str
|
||||
include_tags:
|
||||
description:
|
||||
|
||||
@@ -17,10 +17,10 @@ short_description: Modify and read dconf database
|
||||
description:
|
||||
- This module allows modifications and reading of C(dconf) database. The module is implemented as a wrapper around C(dconf)
|
||||
tool. Please see the dconf(1) man page for more details.
|
||||
- Since C(dconf) requires a running D-Bus session to change values, the module will try to detect an existing session and
|
||||
reuse it, or run the tool using C(dbus-run-session).
|
||||
- Since C(dconf) requires a running D-Bus session to change values, the module tries to detect an existing session and reuse
|
||||
it, or run the tool using C(dbus-run-session).
|
||||
requirements:
|
||||
- Optionally the C(gi.repository) Python library (usually included in the OS on hosts which have C(dconf)); this will become
|
||||
- Optionally the C(gi.repository) Python library (usually included in the OS on hosts which have C(dconf)); this is to become
|
||||
a non-optional requirement in a future major release of community.general.
|
||||
notes:
|
||||
- This module depends on C(psutil) Python library (version 4.0.0 and upwards), C(dconf), C(dbus-send), and C(dbus-run-session)
|
||||
@@ -28,7 +28,7 @@ notes:
|
||||
- This module uses the C(gi.repository) Python library when available for accurate comparison of values in C(dconf) to values
|
||||
specified in Ansible code. C(gi.repository) is likely to be present on most systems which have C(dconf) but may not be
|
||||
present everywhere. When it is missing, a simple string comparison between values is used, and there may be false positives,
|
||||
that is, Ansible may think that a value is being changed when it is not. This fallback will be removed in a future version
|
||||
that is, Ansible may think that a value is being changed when it is not. This fallback is to be removed in a future version
|
||||
of this module, at which point the module will stop working on hosts without C(gi.repository).
|
||||
- Detection of existing, running D-Bus session, required to change settings using C(dconf), is not 100% reliable due to
|
||||
implementation details of D-Bus daemon itself. This might lead to running applications not picking-up changes on-the-fly
|
||||
|
||||
@@ -33,13 +33,12 @@ options:
|
||||
required: true
|
||||
dest:
|
||||
description:
|
||||
- The file name of the destination file where the compressed file will be decompressed.
|
||||
- If the destination file exists, it will be truncated and overwritten.
|
||||
- If not specified, the destination filename will be derived from O(src) by removing the compression format extension.
|
||||
For example, if O(src) is V(/path/to/file.txt.gz) and O(format) is V(gz), O(dest) will be V(/path/to/file.txt). If
|
||||
the O(src) file does not have an extension for the current O(format), the O(dest) filename will be made by appending
|
||||
C(_decompressed) to the O(src) filename. For instance, if O(src) is V(/path/to/file.myextension), the (dest) filename
|
||||
will be V(/path/to/file.myextension_decompressed).
|
||||
- The file name of the destination file where the compressed file is decompressed.
|
||||
- If the destination file exists, it is truncated and overwritten.
|
||||
- If not specified, the destination filename is derived from O(src) by removing the compression format extension. For
|
||||
example, when O(src) is V(/path/to/file.txt.gz) and O(format) is V(gz), O(dest) is V(/path/to/file.txt). If the O(src)
|
||||
file does not have an extension for the current O(format), the O(dest) filename is made by appending C(_decompressed)
|
||||
to the O(src) filename. For instance, when O(src) is V(/path/to/file.myextension), the (dest) filename is V(/path/to/file.myextension_decompressed).
|
||||
type: path
|
||||
format:
|
||||
description:
|
||||
@@ -132,6 +131,7 @@ def decompress(b_src, b_dest, handler):
|
||||
|
||||
class Decompress(ModuleHelper):
|
||||
destination_filename_template = "%s_decompressed"
|
||||
use_old_vardict = False
|
||||
output_params = 'dest'
|
||||
|
||||
module = dict(
|
||||
|
||||
@@ -18,8 +18,8 @@ short_description: Manages some of the steps common in deploying projects
|
||||
description:
|
||||
- The Deploy Helper manages some of the steps common in deploying software. It creates a folder structure, manages a symlink
|
||||
for the current release and cleans up old releases.
|
||||
- Running it with the O(state=query) or O(state=present) will return the C(deploy_helper) fact. C(project_path), whatever
|
||||
you set in the O(path) parameter, C(current_path), the path to the symlink that points to the active release, C(releases_path),
|
||||
- Running it with the O(state=query) or O(state=present) returns the C(deploy_helper) fact. C(project_path), whatever you
|
||||
set in the O(path) parameter, C(current_path), the path to the symlink that points to the active release, C(releases_path),
|
||||
the path to the folder to keep releases in, C(shared_path), the path to the folder to keep shared resources in, C(unfinished_filename),
|
||||
the file to check for to recognize unfinished builds, C(previous_release), the release the 'current' symlink is pointing
|
||||
to, C(previous_release_path), the full path to the 'current' symlink target, C(new_release), either the O(release) parameter
|
||||
@@ -41,12 +41,12 @@ options:
|
||||
type: str
|
||||
description:
|
||||
- The state of the project.
|
||||
- V(query) will only gather facts.
|
||||
- V(present) will create the project C(root) folder, and in it the C(releases) and C(shared) folders.
|
||||
- V(finalize) will remove the unfinished_filename file, create a symlink to the newly deployed release and optionally
|
||||
clean old releases.
|
||||
- V(clean) will remove failed & old releases.
|
||||
- V(absent) will remove the project folder (synonymous to the M(ansible.builtin.file) module with O(state=absent)).
|
||||
- V(query) gathers facts.
|
||||
- V(present) creates the project C(root) folder, and in it the C(releases) and C(shared) folders.
|
||||
- V(finalize) removes the unfinished_filename file, creates a symlink to the newly deployed release and optionally cleans
|
||||
old releases.
|
||||
- V(clean) removes failed & old releases.
|
||||
- V(absent) removes the project folder (synonymous to the M(ansible.builtin.file) module with O(state=absent)).
|
||||
choices: [present, finalize, absent, clean, query]
|
||||
default: present
|
||||
|
||||
@@ -59,15 +59,15 @@ options:
|
||||
releases_path:
|
||||
type: str
|
||||
description:
|
||||
- The name of the folder that will hold the releases. This can be relative to O(path) or absolute. Returned in the C(deploy_helper.releases_path)
|
||||
- The name of the folder that holds the releases. This can be relative to O(path) or absolute. Returned in the C(deploy_helper.releases_path)
|
||||
fact.
|
||||
default: releases
|
||||
|
||||
shared_path:
|
||||
type: path
|
||||
description:
|
||||
- The name of the folder that will hold the shared resources. This can be relative to O(path) or absolute. If this is
|
||||
set to an empty string, no shared folder will be created. Returned in the C(deploy_helper.shared_path) fact.
|
||||
- The name of the folder that holds the shared resources. This can be relative to O(path) or absolute. If this is set
|
||||
to an empty string, no shared folder is created. Returned in the C(deploy_helper.shared_path) fact.
|
||||
default: shared
|
||||
|
||||
current_path:
|
||||
@@ -81,8 +81,8 @@ options:
|
||||
type: str
|
||||
description:
|
||||
- The name of the file that indicates a deploy has not finished. All folders in the O(releases_path) that contain this
|
||||
file will be deleted on O(state=finalize) with O(clean=true), or O(state=clean). This file is automatically deleted
|
||||
from the C(new_release_path) during O(state=finalize).
|
||||
file are deleted on O(state=finalize) with O(clean=true), or O(state=clean). This file is automatically deleted from
|
||||
the C(new_release_path) during O(state=finalize).
|
||||
default: DEPLOY_UNFINISHED
|
||||
|
||||
clean:
|
||||
@@ -95,16 +95,16 @@ options:
|
||||
type: int
|
||||
description:
|
||||
- The number of old releases to keep when cleaning. Used in O(state=finalize) and O(state=clean). Any unfinished builds
|
||||
will be deleted first, so only correct releases will count. The current version will not count.
|
||||
are deleted first, so only correct releases count. The current version does not count.
|
||||
default: 5
|
||||
|
||||
notes:
|
||||
- Facts are only returned for O(state=query) and O(state=present). If you use both, you should pass any overridden parameters
|
||||
to both calls, otherwise the second call will overwrite the facts of the first one.
|
||||
to both calls, otherwise the second call overwrites the facts of the first one.
|
||||
- When using O(state=clean), the releases are ordered by I(creation date). You should be able to switch to a new naming
|
||||
strategy without problems.
|
||||
- Because of the default behaviour of generating the C(new_release) fact, this module will not be idempotent unless you
|
||||
pass your own release name with O(release). Due to the nature of deploying software, this should not be much of a problem.
|
||||
- Because of the default behaviour of generating the C(new_release) fact, this module is not idempotent unless you pass
|
||||
your own release name with O(release). Due to the nature of deploying software, this should not be much of a problem.
|
||||
extends_documentation_fragment:
|
||||
- ansible.builtin.files
|
||||
- community.general.attributes
|
||||
|
||||
@@ -56,8 +56,7 @@ options:
|
||||
state:
|
||||
description:
|
||||
- The desired state for the target VLAN.
|
||||
- V(readonly) ensures that the state is only ever read, not modified (the module will fail if the resource does not
|
||||
exist).
|
||||
- V(readonly) ensures that the state is only ever read, not modified (the module fails if the resource does not exist).
|
||||
choices: [present, absent, readonly]
|
||||
default: present
|
||||
type: str
|
||||
@@ -65,7 +64,7 @@ options:
|
||||
description:
|
||||
- Permit expansion of the target VLAN's network if the module parameters specify a larger network than the VLAN currently
|
||||
possesses.
|
||||
- If V(false), the module will fail under these conditions.
|
||||
- If V(false), the module fails under these conditions.
|
||||
- This is intended to prevent accidental expansion of a VLAN's network (since this operation is not reversible).
|
||||
type: bool
|
||||
default: false
|
||||
|
||||
@@ -22,7 +22,7 @@ options:
|
||||
database:
|
||||
description:
|
||||
- Specify databases to run checks against.
|
||||
- If not specified, Django will not run database tests.
|
||||
- If not specified, Django does not run database tests.
|
||||
type: list
|
||||
elements: str
|
||||
deploy:
|
||||
@@ -32,7 +32,7 @@ options:
|
||||
default: false
|
||||
fail_level:
|
||||
description:
|
||||
- Message level that will trigger failure.
|
||||
- Message level that triggers failure.
|
||||
- Default is the Django default value. Check the documentation for the version being used.
|
||||
type: str
|
||||
choices: [CRITICAL, ERROR, WARNING, INFO, DEBUG]
|
||||
@@ -49,7 +49,7 @@ options:
|
||||
elements: str
|
||||
notes:
|
||||
- The outcome of the module is found in the common return values RV(ignore:stdout), RV(ignore:stderr), RV(ignore:rc).
|
||||
- The module will fail if RV(ignore:rc) is not zero.
|
||||
- The module fails if RV(ignore:rc) is not zero.
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
|
||||
@@ -15,7 +15,7 @@ module: django_manage
|
||||
short_description: Manages a Django application
|
||||
description:
|
||||
- Manages a Django application using the C(manage.py) application frontend to C(django-admin). With the O(virtualenv) parameter,
|
||||
all management commands will be executed by the given C(virtualenv) installation.
|
||||
all management commands are executed by the given C(virtualenv) installation.
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
attributes:
|
||||
@@ -34,8 +34,8 @@ options:
|
||||
- V(loaddata) - Searches for and loads the contents of the named O(fixtures) into the database.
|
||||
- V(migrate) - Synchronizes the database state with models and migrations.
|
||||
- V(test) - Runs tests for all installed apps.
|
||||
- Other commands can be entered, but will fail if they are unknown to Django. Other commands that may prompt for user
|
||||
input should be run with the C(--noinput) flag.
|
||||
- Custom commands can be entered, but they fail unless they are known to Django. Custom commands that may prompt for
|
||||
user input should be run with the C(--noinput) flag.
|
||||
- Support for the values V(cleanup), V(syncdb), V(validate) was removed in community.general 9.0.0. See note about supported
|
||||
versions of Django.
|
||||
type: str
|
||||
@@ -62,7 +62,7 @@ options:
|
||||
virtualenv:
|
||||
description:
|
||||
- An optional path to a C(virtualenv) installation to use while running the manage application.
|
||||
- The virtual environment must exist, otherwise the module will fail.
|
||||
- The virtual environment must exist, otherwise the module fails.
|
||||
type: path
|
||||
aliases: [virtual_env]
|
||||
apps:
|
||||
@@ -78,7 +78,7 @@ options:
|
||||
clear:
|
||||
description:
|
||||
- Clear the existing files before trying to copy or link the original file.
|
||||
- Used only with the V(collectstatic) command. The C(--noinput) argument will be added automatically.
|
||||
- Used only with the V(collectstatic) command. The C(--noinput) argument is added automatically.
|
||||
required: false
|
||||
default: false
|
||||
type: bool
|
||||
@@ -101,18 +101,18 @@ options:
|
||||
required: false
|
||||
skip:
|
||||
description:
|
||||
- Will skip over out-of-order missing migrations, you can only use this parameter with V(migrate) command.
|
||||
- Skips over out-of-order missing migrations, you can only use this parameter with V(migrate) command.
|
||||
required: false
|
||||
type: bool
|
||||
merge:
|
||||
description:
|
||||
- Will run out-of-order or missing migrations as they are not rollback migrations, you can only use this parameter with
|
||||
- Runs out-of-order or missing migrations as they are not rollback migrations, you can only use this parameter with
|
||||
V(migrate) command.
|
||||
required: false
|
||||
type: bool
|
||||
link:
|
||||
description:
|
||||
- Will create links to the files instead of copying them, you can only use this parameter with V(collectstatic) command.
|
||||
- Creates links to the files instead of copying them, you can only use this parameter with V(collectstatic) command.
|
||||
required: false
|
||||
type: bool
|
||||
testrunner:
|
||||
@@ -122,13 +122,19 @@ options:
|
||||
type: str
|
||||
required: false
|
||||
aliases: [test_runner]
|
||||
ack_venv_creation_deprecation:
|
||||
description:
|
||||
- This option no longer has any effect since community.general 9.0.0.
|
||||
- It will be removed from community.general 11.0.0.
|
||||
type: bool
|
||||
version_added: 5.8.0
|
||||
|
||||
notes:
|
||||
- 'B(ATTENTION): Support for Django releases older than 4.1 has been removed in community.general version 9.0.0. While the
|
||||
module allows for free-form commands, not verifying the version of Django being used, it is B(strongly recommended) to
|
||||
use a more recent version of the framework.'
|
||||
- Please notice that Django 4.1 requires Python 3.8 or greater.
|
||||
- This module will not create a virtualenv if the O(virtualenv) parameter is specified and a virtual environment does not
|
||||
- This module does not create a virtualenv if the O(virtualenv) parameter is specified and a virtual environment does not
|
||||
already exist at the given location. This behavior changed in community.general version 9.0.0.
|
||||
- The recommended way to create a virtual environment in Ansible is by using M(ansible.builtin.pip).
|
||||
- This module assumes English error messages for the V(createcachetable) command to detect table existence, unfortunately.
|
||||
@@ -285,6 +291,7 @@ def main():
|
||||
skip=dict(type='bool'),
|
||||
merge=dict(type='bool'),
|
||||
link=dict(type='bool'),
|
||||
ack_venv_creation_deprecation=dict(type='bool', removed_in_version='11.0.0', removed_from_collection='community.general'),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ changed_repos:
|
||||
returned: success
|
||||
type: list
|
||||
elements: str
|
||||
sample: ['crb']
|
||||
sample: ["crb"]
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
@@ -22,9 +22,9 @@ attributes:
|
||||
support: partial
|
||||
details:
|
||||
- The logics of the C(versionlock) plugin for corner cases could be confusing, so please take in account that this module
|
||||
will do its best to give a C(check_mode) prediction on what is going to happen. In case of doubt, check the documentation
|
||||
does its best to give a C(check_mode) prediction on what is going to happen. In case of doubt, check the documentation
|
||||
of the plugin.
|
||||
- Sometimes the module could predict changes in C(check_mode) that will not be such because C(versionlock) concludes
|
||||
- Sometimes the module could predict changes in C(check_mode) that are not fulfilled because C(versionlock) concludes
|
||||
that there is already a entry in C(locklist) that already matches.
|
||||
diff_mode:
|
||||
support: none
|
||||
@@ -47,12 +47,12 @@ options:
|
||||
state:
|
||||
description:
|
||||
- Whether to add (V(present) or V(excluded)) to or remove (V(absent) or V(clean)) from the C(locklist).
|
||||
- V(present) will add a package name spec to the C(locklist). If there is a installed package that matches, then only
|
||||
that version will be added. Otherwise, all available package versions will be added.
|
||||
- V(excluded) will add a package name spec as excluded to the C(locklist). It means that packages represented by the
|
||||
package name spec will be excluded from transaction operations. All available package versions will be added.
|
||||
- V(absent) will delete entries in the C(locklist) that match the package name spec.
|
||||
- V(clean) will delete all entries in the C(locklist). This option is mutually exclusive with O(name).
|
||||
- V(present) adds a package name spec to the C(locklist). If there is a installed package that matches, then only that
|
||||
version is added. Otherwise, all available package versions are added.
|
||||
- V(excluded) adds a package name spec as excluded to the C(locklist). It means that packages represented by the package
|
||||
name spec are excluded from transaction operations. All available package versions are added.
|
||||
- V(absent) deletes entries in the C(locklist) that match the package name spec.
|
||||
- V(clean) deletes all entries in the C(locklist). This option is mutually exclusive with O(name).
|
||||
choices: ['absent', 'clean', 'excluded', 'present']
|
||||
type: str
|
||||
default: present
|
||||
@@ -108,25 +108,25 @@ locklist_pre:
|
||||
returned: success
|
||||
type: list
|
||||
elements: str
|
||||
sample: ['bash-0:4.4.20-1.el8_4.*', '!bind-32:9.11.26-4.el8_4.*']
|
||||
sample: ["bash-0:4.4.20-1.el8_4.*", "!bind-32:9.11.26-4.el8_4.*"]
|
||||
locklist_post:
|
||||
description: Locklist after module execution.
|
||||
returned: success and (not check mode or state is clean)
|
||||
type: list
|
||||
elements: str
|
||||
sample: ['bash-0:4.4.20-1.el8_4.*']
|
||||
sample: ["bash-0:4.4.20-1.el8_4.*"]
|
||||
specs_toadd:
|
||||
description: Package name specs meant to be added by versionlock.
|
||||
returned: success
|
||||
type: list
|
||||
elements: str
|
||||
sample: ['bash']
|
||||
sample: ["bash"]
|
||||
specs_todelete:
|
||||
description: Package name specs meant to be deleted by versionlock.
|
||||
returned: success
|
||||
type: list
|
||||
elements: str
|
||||
sample: ['bind']
|
||||
sample: ["bind"]
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
@@ -25,8 +25,8 @@ attributes:
|
||||
options:
|
||||
account_email:
|
||||
description:
|
||||
- Account email. If omitted, the environment variables E(DNSIMPLE_EMAIL) and E(DNSIMPLE_API_TOKEN) will be looked for.
|
||||
- 'If those variables are not found, a C(.dnsimple) file will be looked for, see: U(https://github.com/mikemaccana/dnsimple-python#getting-started).'
|
||||
- Account email. If omitted, the environment variables E(DNSIMPLE_EMAIL) and E(DNSIMPLE_API_TOKEN) are looked for.
|
||||
- 'If those variables are not found, a C(.dnsimple) file is looked for, see: U(https://github.com/mikemaccana/dnsimple-python#getting-started).'
|
||||
- C(.dnsimple) config files are only supported in dnsimple-python<2.0.0.
|
||||
type: str
|
||||
account_api_token:
|
||||
@@ -36,12 +36,12 @@ options:
|
||||
domain:
|
||||
description:
|
||||
- Domain to work with. Can be the domain name (for example V(mydomain.com)) or the numeric ID of the domain in DNSimple.
|
||||
- If omitted, a list of domains will be returned.
|
||||
- If domain is present but the domain does not exist, it will be created.
|
||||
- If omitted, a list of domains is returned.
|
||||
- If domain is present but the domain does not exist, it is created.
|
||||
type: str
|
||||
record:
|
||||
description:
|
||||
- Record to add, if blank a record for the domain will be created, supports the wildcard (*).
|
||||
- Record to add, if blank a record for the domain is created, supports the wildcard (*).
|
||||
type: str
|
||||
record_ids:
|
||||
description:
|
||||
|
||||
@@ -26,8 +26,8 @@ options:
|
||||
name:
|
||||
description:
|
||||
- The domain name to retrieve info from.
|
||||
- Will return all associated records for this domain if specified.
|
||||
- If not specified, will return all domains associated with the account ID.
|
||||
- Returns all associated records for this domain if specified.
|
||||
- If not specified, returns all domains associated with the account ID.
|
||||
type: str
|
||||
|
||||
account_id:
|
||||
@@ -43,7 +43,7 @@ options:
|
||||
record:
|
||||
description:
|
||||
- The record to find.
|
||||
- If specified, only this record will be returned instead of all records.
|
||||
- If specified, only this record is returned instead of all records.
|
||||
required: false
|
||||
type: str
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ options:
|
||||
|
||||
record_name:
|
||||
description:
|
||||
- Record name to get/create/delete/update. If record_name is not specified; all records for the domain will be returned
|
||||
- Record name to get/create/delete/update. If O(record_name) is not specified; all records for the domain are returned
|
||||
in "result" regardless of the state argument.
|
||||
type: str
|
||||
|
||||
@@ -64,8 +64,8 @@ options:
|
||||
description:
|
||||
- 'Record value. HTTPRED: <redirection URL>, MX: <priority> <target name>, NS: <name server>, PTR: <target name>, SRV:
|
||||
<priority> <weight> <port> <target name>, TXT: <text value>".'
|
||||
- If record_value is not specified; no changes will be made and the record will be returned in 'result' (in other words,
|
||||
this module can be used to fetch a record's current ID, type, and ttl).
|
||||
- If O(record_value) is not specified; no changes are made and the record is returned in RV(ignore:result) (in other
|
||||
words, this module can be used to fetch a record's current ID, type, and TTL).
|
||||
type: str
|
||||
|
||||
record_ttl:
|
||||
@@ -83,8 +83,8 @@ options:
|
||||
|
||||
validate_certs:
|
||||
description:
|
||||
- If V(false), SSL certificates will not be validated. This should only be used on personally controlled sites using
|
||||
self-signed certificates.
|
||||
- If V(false), SSL certificates are not validated. This should only be used on personally controlled sites using self-signed
|
||||
certificates.
|
||||
type: bool
|
||||
default: true
|
||||
|
||||
@@ -128,7 +128,7 @@ options:
|
||||
|
||||
contactList:
|
||||
description:
|
||||
- Name or ID of the contact list that the monitor will notify.
|
||||
- Name or ID of the contact list that the monitor notifies.
|
||||
- The default V('') means the Account Owner.
|
||||
type: str
|
||||
|
||||
@@ -195,7 +195,7 @@ notes:
|
||||
- Only A records can have a O(monitor) or O(failover).
|
||||
- To add failover, the O(failover), O(autoFailover), O(port), O(protocol), O(ip1), and O(ip2) options are required.
|
||||
- To add monitor, the O(monitor), O(port), O(protocol), O(maxEmails), O(systemDescription), and O(ip1) options are required.
|
||||
- The monitor and the failover will share O(port), O(protocol), and O(ip1) options.
|
||||
- The options O(monitor) and O(failover) share O(port), O(protocol), and O(ip1) options.
|
||||
requirements: [hashlib, hmac]
|
||||
author: "Brice Burgess (@briceburg)"
|
||||
"""
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user