Including var file in playbook and pass it to role

36 views
Skip to first unread message

Eugene Knoxville

unread,
Jul 21, 2015, 8:50:57 AM7/21/15
to ansible...@googlegroups.com
Hello,

Have some troubles with including var files. What I need? I keep authorized_keys files for each user in a separate file. For exmpl, let's say that hostname is f22.

Playbook f22.yml:

---
- hosts: f22 
  tasks:
    - include: tasks/mainsoftware.yml
 
  vars_files:
    - /etc/ansible/files/pub_keys/f22/ssh_user
    - /etc/ansible/files/pub_keys/f22/allow_users
        
  roles:
     - { role: ssh.role, ssh_user: "{{ ssh_user}}" , allow_users:"{{ allow_users }}" }

/etc/ansible/files/pub_keys/f22/ssh_user:

---
ssh_user: test1
ssh_user: test2


/etc/ansible/files/pub_keys/f22/allow_users:

---
allow_users: test1 test2 


ssh.role file:

- name: Creating authorized_keys file
  template: src=root-keys dest=/root/.ssh/authorized_keys mode=600 owner=0 group=0

- name: Creating id_rsa file
  template: src=id_rsa dest=/root/.ssh/id_rsa mode=600 owner=0 group=0

- name: sshd configuration file update
  template: src=sshd_config
      dest=/etc/ssh/sshd_config
      backup=yes
      owner=0 group=0 mode=0644
      validate='/usr/sbin/sshd -T -f %s'
  when: ansible_system == "Linux"
  notify:
    - restart sshd

- name: Create users
  user: name="{{ ssh_user }}" generate_ssh_key=no comment="{{ ssh_user }} user"
#  with_items: "{{ ssh_user }}"
  
- name: Add pub files  
  authorized_key: user="{{ ssh_user }}" key="{{ item }}"
  with_file: /etc/ansible/files/pub_keys/{{ansible_hostname}}/{{ ssh_user }}.pub
#  with_items: "{{ ssh_user }}"

- name: add AllowUsers
  lineinfile: dest=/etc/ssh/sshd_config line="AllowUsers {{ allow_users }}"
  notify: 
    - restart sshd
    
- name: sshd configuration file update FreeBSD
  template: src=sshd_config_free
      dest=/etc/ssh/sshd_config
      backup=yes
      owner=0 group=0 mode=0644
      validate='/usr/sbin/sshd -T -f %s'
  when: ansible_system == "FreeBSD"
  notify:
    - restart sshd


After applying, I'm getting:




Please help :) 

Message has been deleted

Eugene Knoxville

unread,
Jul 21, 2015, 10:51:53 AM7/21/15
to ansible...@googlegroups.com
I put vars in host_vars/f22 file  - and It Works! :) 
Reply all
Reply to author
Forward
0 new messages