###前提・実現したいこと
Ansibleで環境変数を参照してコマンドを実行したいのですが、 group_vars/all
で宣言している変数参照時にエラーが出てしまいます。
書式などに初歩的なミスがありますでしょうか?
ご協力のほど、よろしくお願いいたします。
###発生している問題・エラーメッセージ
the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'unicode object' has no attribute 'gid' The error appears to have been in '/vagrant/ansible/roles/test/tasks/main.yml': line 7, column 3, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: - name: create groups debug ^ here
[root@localhost ansible]# ansible-playbook test.yml --limit=vagrant --connection=local -vvvv Using /vagrant/ansible/ansible.cfg as config file Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc PLAYBOOK: test.yml ************************************************************* 1 plays in test.yml PLAY [all] ********************************************************************* TASK [setup] ******************************************************************* Using module file /usr/lib/python2.7/site-packages/ansible/modules/core/system/setup.py <127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root <127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1479267155.59-84022657785728 `" && echo ansible-tmp-1479267155.59-84022657785728="` echo $HOME/.ansible/tmp/ansible-tmp-1479267155.59-84022657785728 `" ) && sleep 0' <127.0.0.1> PUT /tmp/tmpKJgvMU TO /root/.ansible/tmp/ansible-tmp-1479267155.59-84022657785728/setup.py <127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1479267155.59-84022657785728/ /root/.ansible/tmp/ansible-tmp-1479267155.59-84022657785728/setup.py && sleep 0' <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1479267155.59-84022657785728/setup.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1479267155.59-84022657785728/" > /dev/null 2>&1 && sleep 0' ok: [127.0.0.1] TASK [test : create groups debug] ********************************************** task path: /vagrant/ansible/roles/test/tasks/main.yml:2 ok: [127.0.0.1] => (item=user_groups) => { "invocation": { "module_args": { "var": "user_groups" }, "module_name": "debug" }, "item": "user_groups", "user_groups": [ { "gid": 1111, "name": "hoge" }, { "gid": 1112, "name": "foo" }, { "gid": 1113, "name": "bar" } ] } TASK [test : create groups debug] ********************************************** task path: /vagrant/ansible/roles/test/tasks/main.yml:7 fatal: [127.0.0.1]: FAILED! => { "failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'unicode object' has no attribute 'gid'\n\nThe error appears to have been in '/vagrant/ansible/roles/test/tasks/main.yml': line 7, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: create groups debug\n ^ here\n" } to retry, use: --limit @/vagrant/ansible/test.retry PLAY RECAP ********************************************************************* 127.0.0.1 : ok=2 changed=0 unreachable=0 failed=1 [root@localhost ansible]#
###該当のソースコード
- 構成
bash
1$ tree 2. 3├── ansible.cfg 4├── group_vars/ 5│ └── all 6├── hosts/ 7├── host_vars/ 8├── roles/ 9│ └── test/ 10│ ├── defaults/ 11│ ├── files/ 12│ ├── handlers/ 13│ ├── meta/ 14│ ├── tasks/ 15│ │ └── main.yml 16│ ├── templates/ 17│ └── vars/ 18└── test.yml 19$ cat ansible.cfg 20[defaults] 21hostfile = ./hosts 22#private_key_file = ~/.vagrant.d/insecure_private_key 23host_key_checking = False 24deprecation_warnings=False 25$ cat group_vars/all 26user_groups: 27 - { name: 'hoge', gid: 1111 } 28 - { name: 'foo', gid: 1112 } 29 - { name: 'bar', gid: 1113 } 30$ cat hosts 31[vagrant] 32127.0.0.1 ansible_connection=local 33$ cat roles/test/tasks/main.yml 34--- 35- name: create groups debug 36 debug: var={{ item }} 37 with_items: user_groups 38 tags: user 39 40- name: create groups debug 41 debug: var={{ item.gid }} 42 with_items: user_groups 43 tags: user 44 45$ cat test.yml 46--- 47- hosts: all 48 remote_user: root 49 roles: 50 - test 51 52$
###試したこと
以前、ほぼこれと同様のコードで上手く動作しておりましたが、いつの間にか動作しなくなっておりました。
Linux OS上で yum update
をおこなっているので、以前と比較するとpythonやansibleのバージョンは上がっております。
変数書式を {{ item.gid }}
から {{ item.['gid'] }}
に変更しましたが、こちらも同じエラーが出てしまいました。
###補足情報(言語/FW/ツール等のバージョンなど)
- Mac OSX
- Vagrant 1.8.1
- VirtualBox 5.0.26
- CentOS Linux release 7.2.1511 (Core)
- Python 2.7.5
- ansible 2.2.0.0
- CentOS Linux release 7.2.1511 (Core)
回答1件
あなたの回答
tips
プレビュー