質問はJSON シリアライズ可能でないインライン暗号化変数に似ています
多くのプレーン テキストと 1 つの暗号化された値を含む Ansible 構成ファイルがあります。
config_value: "something in plain text"
another_value: "another plain text value"
my_secret: !vault |
$ANSIBLE_VAULT;1.1;AES256
36343434346535636131316538313039386539363337326432336330393734306562336563386335
3663323065343330303039655530313833623439616630320a323730613534613338326263386136
33313033363737626230343432363764356336346363306466356330633561353831346433333366
3964386161306338300a333164333932333539333565303038643462643137663438326664336431
66613433396133633039385664366564626231313230383464356537636434646534
ここで説明する次の方法で変数を暗号化しました。
ansible-vault encrypt_string --vault-password-file path/to/password testvalue
実行するinclude_vars
と、次のエラー メッセージが表示されます。
TASK [include_vars] ************************************************************
task path: /var/jenkins_home/workspace/path/to/deploy-playbook.yml:21
[WARNING]: Failure using method (v2_runner_on_ok) in callback plugin
(<ansible.plugins.callback.default.CallbackModule object at 0x7f37a284fa90>):
u'testvalue' is not JSON serializable
Callback Exception:
File "/var/jenkins_home/workspace/path/to/virtualenv/local/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 375, in send_callback
method(*new_args, **kwargs)
File "/var/jenkins_home/workspace/path/to/virtualenv/local/lib/python2.7/site-packages/ansible/plugins/callback/default.py", line 100, in v2_runner_on_ok
msg += " => %s" % (self._dump_results(result._result),)
File "/var/jenkins_home/workspace/path/to/virtualenv/local/lib/python2.7/site-packages/ansible/plugins/callback/__init__.py", line 107, in _dump_results
return json.dumps(abridged_result, indent=indent, ensure_ascii=False, sort_keys=sort_keys)
File "/usr/lib/python2.7/json/__init__.py", line 251, in dumps
sort_keys=sort_keys, **kw).encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 209, in encode
chunks = list(chunks)
File "/usr/lib/python2.7/json/encoder.py", line 434, in _iterencode
for chunk in _iterencode_dict(o, _current_indent_level):
File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
for chunk in chunks:
File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
for chunk in chunks:
File "/usr/lib/python2.7/json/encoder.py", line 442, in _iterencode
o = _default(o)
File "/usr/lib/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
また、シークレットを暗号化するために次のコマンドを試しましたが、うまくいきませんでした:
ansible-vault encrypt_string --vault-password-file path/to/password 'testvalue'
ansible-vault encrypt_string --vault-password-file path/to/password "testvalue'
ansible-vault encrypt_string --vault-password-file path/to/password "'testvalue'"