※エラーメッセージの記述を間違えていた為、修正しました。
いつも助けて頂いてありがとうございます。下記を実現する方法がもしあれば教えて頂けると助かります。自身も本当に出来るのかわからず探りながらやってます。
実現したいこと
・パラメータ情報が記載された外部ファイル(json)を読み込み、jinja2テンプレートに入れた(入れて加工したいのですが、加工の内容はまだ決めてません)後
後続のタスクでパラメータを個別に指定して呼び出し使用したい。
・上記を一枚のPlaybookで完結させたい。
・"{{ 変数名.パラメータ値 }}"という形で呼び出したいけど、他の形でも方法があるのか知りたい。
該当のソースコード
test.yml
1- hosts: fortigates 2 collections: 3 - fortinet.fortios 4 connection: httpapi 5 vars: 6 ansible_httpapi_use_ssl: yes 7 ansible_httpapi_validate_certs: no 8 ansible_httpapi_port: 443 9 test1: "{{ lookup('file', '/srv/data/parameter.json') }}" 10 test2: "{{ lookup('template', '/srv/data/parameter.j2', template_vars=test1) }}" 11 tasks: 12 - name: set_factest 13 set_fact: 14 parameter: "{{ test2 }}" 15 - name: debug 16 debug: 17 msg: "{{ parameter }}" 18 - name: system_global 19 fortios_system_global: 20 system_global: 21 language: "{{ parameter.language }}" 22 23------------------------------------------------------------------------------------------------------- 24 25■parameter.json 26{ 27 "timezone": "60", 28 "hostname": "FGT60FTK21035539", 29 "language": "japanese" 30} 31 32■parameter.j2 33{ 34 "timezone": "{{ timezone }}", 35 "hostname": "{{ hostname }}", 36 "language": "{{ language }}" 37} 38 39------------------------------------------------------------------------------------------------------- 40■実行結果&エラーメッセージ 41 42TASK 2/3 [set_factest] *********************************************************************************************************** 43task path: /etc/ansible/fortigate/test/template/test.yml:12 44redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi 45ok: 1/1 [ansible_host=192.168.1.1] => { 46 "ansible_facts": { 47 "parameter": { 48 "hostname": "FGT60FTK21035539", 49 "language": "japanese", 50 "timezone": "60" 51 } 52 }, 53 "changed": false 54} 55 56TASK 3/3 [debug] ***************************************************************************************************************** 57task path: /etc/ansible/fortigate/test/template/test.yml:15 58redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi 59ok: 1/1 [ansible_host=192.168.1.1] => { 60 "msg": "japanese" 61} 62 63TASK 4/3 [system_global] ********************************************************************************************************* 64task path: /etc/ansible/fortigate/test/template/test.yml:18 65redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi 66<ansible_host=192.168.1.1> ESTABLISH LOCAL CONNECTION FOR USER: root 67<ansible_host=192.168.1.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-2547325cxuhn6 `"&& mkdir "` echo /root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319 `" && echo ansible-tmp-1661990706.1743524-25588-27745780406319="` echo /root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319 `" ) && sleep 0' 68Using module file /root/.ansible/collections/ansible_collections/fortinet/fortios/plugins/modules/fortios_system_global.py 69<ansible_host=192.168.1.1> PUT /root/.ansible/tmp/ansible-local-2547325cxuhn6/tmpxygvkwnr TO /root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319/AnsiballZ_fortios_system_global.py 70<ansible_host=192.168.1.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319/ /root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319/AnsiballZ_fortios_system_global.py && sleep 0' 71<ansible_host=192.168.1.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319/AnsiballZ_fortios_system_global.py && sleep 0' 72<ansible_host=192.168.1.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319/ > /dev/null 2>&1 && sleep 0' 73The full traceback is: 74Traceback (most recent call last): 75 File "/root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319/AnsiballZ_fortios_system_global.py", line 100, in <module> 76 _ansiballz_main() 77 File "/root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319/AnsiballZ_fortios_system_global.py", line 92, in _ansiballz_main 78 invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS) 79 File "/root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319/AnsiballZ_fortios_system_global.py", line 41, in invoke_module 80 run_name='__main__', alter_sys=True) 81 File "/usr/lib64/python3.6/runpy.py", line 205, in run_module 82 return _run_module_code(code, init_globals, run_name, mod_spec) 83 File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code 84 mod_name, mod_spec, pkg_name, script_name) 85 File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code 86 exec(code, run_globals) 87 File "/tmp/ansible_fortios_system_global_payload_j54iq53b/ansible_fortios_system_global_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_system_global.py", line 15222, in <module> 88 File "/tmp/ansible_fortios_system_global_payload_j54iq53b/ansible_fortios_system_global_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_system_global.py", line 15199, in main 89 File "/tmp/ansible_fortios_system_global_payload_j54iq53b/ansible_fortios_system_global_payload.zip/ansible_collections/fortinet/fortios/plugins/module_utils/fortios/fortios.py", line 216, in check_schema_versioning 90 File "/tmp/ansible_fortios_system_global_payload_j54iq53b/ansible_fortios_system_global_payload.zip/ansible/module_utils/connection.py", line 200, in __rpc__ 91ansible.module_utils.connection.ConnectionError: Method not found 92fatal: 1/1 [ansible_host=192.168.1.1]: FAILED! => { 93 "changed": false, 94 "module_stderr": "Traceback (most recent call last):\n File \"/root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319/AnsiballZ_fortios_system_global.py\", line 100, in <module>\n _ansiballz_main()\n File \"/root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319/AnsiballZ_fortios_system_global.py\", line 92, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/root/.ansible/tmp/ansible-local-2547325cxuhn6/ansible-tmp-1661990706.1743524-25588-27745780406319/AnsiballZ_fortios_system_global.py\", line 41, in invoke_module\n run_name='__main__', alter_sys=True)\n File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n mod_name, mod_spec, pkg_name, script_name)\n File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_fortios_system_global_payload_j54iq53b/ansible_fortios_system_global_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_system_global.py\", line 15222, in <module>\n File \"/tmp/ansible_fortios_system_global_payload_j54iq53b/ansible_fortios_system_global_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_system_global.py\", line 15199, in main\n File \"/tmp/ansible_fortios_system_global_payload_j54iq53b/ansible_fortios_system_global_payload.zip/ansible_collections/fortinet/fortios/plugins/module_utils/fortios/fortios.py\", line 216, in check_schema_versioning\n File \"/tmp/ansible_fortios_system_global_payload_j54iq53b/ansible_fortios_system_global_payload.zip/ansible/module_utils/connection.py\", line 200, in __rpc__\nansible.module_utils.connection.ConnectionError: Method not found\n", 95 "module_stdout": "", 96 "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", 97 "rc": 1 98} 99 100PLAY RECAP *********************************************************************************************************************** 101ansible_host=192.168.1.1 : ok=3 changed=0 unreachable=0 failed=1 rescued=0 ignored=0

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/01 03:10