質問するログイン新規登録

質問編集履歴

4

書式修正

2020/05/20 01:58

投稿

papachiropa
papachiropa

スコア15

title CHANGED
File without changes
body CHANGED
@@ -7,8 +7,8 @@
7
7
 
8
8
  ### /tmp/group_vars/users.yml
9
9
  > users:
10
- <span> </span> '- { name: 'a', uid: 123, group: 'x' }
10
+ '- { name: 'a', uid: 123, group: 'x' }
11
- <span> </span> '- { name: 'b', uid: 124, group: 'x' }
11
+ '- { name: 'b', uid: 124, group: 'x' }
12
12
 
13
13
  ### /tmp/setup.yml
14
14
  > - hosts: 192.168.100.251

3

書式変更

2020/05/20 01:58

投稿

papachiropa
papachiropa

スコア15

title CHANGED
File without changes
body CHANGED
@@ -7,8 +7,8 @@
7
7
 
8
8
  ### /tmp/group_vars/users.yml
9
9
  > users:
10
- '- { name: 'a', uid: 123, group: 'x' }
10
+ <span> </span> '- { name: 'a', uid: 123, group: 'x' }
11
- '- { name: 'b', uid: 124, group: 'x' }
11
+ <span> </span> '- { name: 'b', uid: 124, group: 'x' }
12
12
 
13
13
  ### /tmp/setup.yml
14
14
  > - hosts: 192.168.100.251

2

エラー内容変更

2020/05/20 01:57

投稿

papachiropa
papachiropa

スコア15

title CHANGED
File without changes
body CHANGED
@@ -1,17 +1,26 @@
1
1
  Ansibleを用いて構築対象サーバ(192.168.100.251)にグループxとユーザa,bを新規で作成し、
2
2
  a,bをxに所属させたいのですがエラーが出ます。OSはAnsible操作端末も構築対象サーバもCentOS7です。
3
- また下記いずれのymlファイルも/tmp配下にあります。
4
3
 
5
- ### addgroup.yml(※以降、行頭の「'」は実際は入っおりません
4
+ ### /tmp/group_vars/user_groups.yml(※以降、ハイフン前の「'」は無視し下さい
6
- > groups:
5
+ > user_groups:
7
- '- { name: 'x', gid: 100 }
6
+ '- { name: 'x', gid: 100 }
8
7
 
9
- ### adduser.yml
8
+ ### /tmp/group_vars/users.yml
10
9
  > users:
11
- '- { name: 'a', uid: 123, group: 'x' }
10
+ '- { name: 'a', uid: 123, group: 'x' }
12
- '- { name: 'b', uid: 124, group: 'x' }
11
+ '- { name: 'b', uid: 124, group: 'x' }
13
12
 
14
- ### create_user_group.yml
13
+ ### /tmp/setup.yml
14
+ > - hosts: 192.168.100.251
15
+ remote_user: root
16
+ become: true
17
+ roles:
18
+ '- setup
19
+ vars_files:
20
+ '- group_vars/user_groups.yml
21
+ '- group_vars/users.yml
22
+
23
+ ### /tmp/roles/useradd/task/create_user_group.yml
15
24
  > '- hosts: 192.168.100.251
16
25
  remote_user: root
17
26
  become: true
@@ -22,7 +31,7 @@
22
31
  gid: "{{ item.gid }}"
23
32
  state: present
24
33
  with_items:
25
- '- "{{ groups }}"
34
+ '- "{{ user_groups }}"
26
35
 
27
36
  > '- name: create user
28
37
  user:
@@ -33,20 +42,20 @@
33
42
  '- "{{ users }}"
34
43
 
35
44
  ### 実行結果
36
- [root@HOGE tmp]# ansible-playbook /tmp/create_user_group.yml
45
+ [root@HOGE tmp]# ansible-playbook /tmp/roles/useradd/task/create_user_group.yml
37
46
 
38
- PLAY [192.168.100.251] *****************************************************************************************************************
47
+ PLAY [192.168.100.251] ****************************************************************************************************************************
39
48
 
40
- TASK [Gathering Facts] *****************************************************************************************************************
49
+ TASK [Gathering Facts] ****************************************************************************************************************************
41
50
  Enter passphrase for key '/root/.ssh/id_rsa':
42
51
  ok: [192.168.100.251]
43
52
 
44
- TASK [create group] ********************************************************************************************************************
45
- fatal: [192.168.100.251]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'gid'\n\nThe error appears to have been in '/tmp/create_user_group.yml': line 7, column 8, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks: \n - name: create group\n ^ here\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'dict object' has no attribute 'gid'"}
46
- to retry, use: --limit @/tmp/create_user_group.retry
53
+ TASK [create group] *******************************************************************************************************************************
54
+ fatal: [192.168.100.251]: FAILED! => {"msg": "'user_groups' is undefined"}
55
+ to retry, use: --limit @/tmp/roles/useradd/task/create_user_group.retry
47
56
 
48
- PLAY RECAP *****************************************************************************************************************************
57
+ PLAY RECAP ****************************************************************************************************************************************
49
58
  192.168.100.251 : ok=1 changed=0 unreachable=0 failed=1
50
59
 
51
- エラーメッセージを調べてもどこの箇所が誤っているか分からなかっので
60
+ 修正致しまし
52
61
  ご教示いただけますと幸いです。宜しくお願い致します。

1

Markdown記法挿入

2020/05/20 01:48

投稿

papachiropa
papachiropa

スコア15

title CHANGED
File without changes
body CHANGED
@@ -3,16 +3,16 @@
3
3
  また下記いずれのymlファイルも/tmp配下にあります。
4
4
 
5
5
  ### addgroup.yml(※以降、行頭の「'」は実際は入っておりません)
6
- groups:
6
+ > groups:
7
7
  '- { name: 'x', gid: 100 }
8
8
 
9
9
  ### adduser.yml
10
- users:
10
+ > users:
11
11
  '- { name: 'a', uid: 123, group: 'x' }
12
12
  '- { name: 'b', uid: 124, group: 'x' }
13
13
 
14
14
  ### create_user_group.yml
15
- '- hosts: 192.168.100.251
15
+ > '- hosts: 192.168.100.251
16
16
  remote_user: root
17
17
  become: true
18
18
  tasks:
@@ -24,13 +24,14 @@
24
24
  with_items:
25
25
  '- "{{ groups }}"
26
26
 
27
- '- name: create user
27
+ > '- name: create user
28
28
  user:
29
29
  name: "{{ item.name }}"
30
30
  uid: "{{ item.uid }}"
31
31
  groups: "{{ item.group }}"
32
32
  with_items:
33
33
  '- "{{ users }}"
34
+
34
35
  ### 実行結果
35
36
  [root@HOGE tmp]# ansible-playbook /tmp/create_user_group.yml
36
37