Discussion:
[ansible-project] Including var file in playbook and pass it to role
Eugene Knoxville
2015-07-21 12:48:48 UTC
Permalink
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:*


<Loading Image...>



Please help :)
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/323a5abd-7420-4bd2-92f8-e7550e953ebd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Eugene Knoxville
2015-07-21 14:50:49 UTC
Permalink
втПрМОк, 21 Оюля 2015 г., 15:50:57 UTC+3 пПльзПватель Eugene Knoxville
Post by Eugene Knoxville
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.
---
- hosts: f22
- include: tasks/mainsoftware.yml
- /etc/ansible/files/pub_keys/f22/ssh_user
- /etc/ansible/files/pub_keys/f22/allow_users
- { role: ssh.role, ssh_user: "{{ ssh_user}}" , allow_users:"{{
allow_users }}" }
---
ssh_user: test1
ssh_user: test2
---
allow_users: test1 test2
- 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"
- 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 }}"
- 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"
- restart sshd
*After applying, I'm getting:*
<https://lh3.googleusercontent.com/-rptaNEEJy7w/Va49VSQSyeI/AAAAAAAAA7k/BN2iCnzT-aY/s1600/Selection_135.png>
Please help :)
I put variables in host_vars/f22 file - and It works :)
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a3f20707-e70f-4453-9d34-775f8bed8d08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Eugene Knoxville
2015-07-21 14:51:53 UTC
Permalink
I put vars in host_vars/f22 file - and It Works! :)
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5a00c0ef-6480-42a1-80ef-3c9c41f17686%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...