[student@workstation lab-roles]$ mv mkcd.sh.j2 roles/student.myenv/templates/
[student@workstation lab-roles]$ cp /usr/share/icons/hicolor/48x48/apps/system-logo-icon.png roles/student.myenv/files/profile.png
[student@workstation lab-roles]$ vi roles/student.myenv/tasks/main.yml
[student@workstation lab-roles]$ cat roles/student.myenv/tasks/main.yml
---
# tasks file for student.myenv
- name: check myenv_user default
fail:
msg: You must specify the variale 'myenv_user' to use this role!
when: "myenv_user == ''"
- name: install my packages
yum:
name: "{{ item }}"
state: installed
with_items: "{{ myenv_packages }}"
- name: copy placeholder profile pic
copy:
src: profile.png
dest: "~{{ myenv_user }}/profile.png"
- name: set an alias in '.bashrc'
copy:
src: profile.png
dest: "~{{ myenv_user }}/.bashrc"
- name: template out mkcd function
template:
src: mkcd.sh.j2
dest: /etc/profile.d/mkcd.sh
owner: root
group: root
mode: 0644
[student@workstation lab-roles]$ vi roles/student.myenv/vars/main.yml
[student@workstation lab-roles]$ cat roles/student.myenv/vars/main.yml
---
# vars file for student.myenv
myenv_packages:
- 'git'
- 'tree'
- 'vim-enhanced'
[student@workstation lab-roles]$ vi roles/student.myenv/defaults/main.yml
[student@workstation lab-roles]$ cat roles/student.myenv/defaults/main.yml
---
# defaults file for student.myenv
myenv_user: ''
[student@workstation lab-roles]$ vi myenv.yml
[student@workstation lab-roles]$ cat roles/student.myenv/defaults/main.yml
---
# defaults file for student.myenv
myenv_user: ''
[student@workstation lab-roles]$ cat myenv.yml
---
- name: setup my personal environment
hosts: all
roles:
- student.myenv
[student@workstation lab-roles]$ ansible-playbook myenv.yml
PLAY [setup my personal environment] ******************************************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [serverb.lab.example.com]
ok: [serverc.lab.example.com]
TASK [student.myenv : check myenv_user default] *******************************************************************************************************************************************************************
fatal: [serverb.lab.example.com]: FAILED! => {"changed": false, "failed": true, "msg": "You must specify the variale 'myenv_user' to use this role!"}
fatal: [serverc.lab.example.com]: FAILED! => {"changed": false, "failed": true, "msg": "You must specify the variale 'myenv_user' to use this role!"}
to retry, use: --limit @/home/student/lab-roles/myenv.retry
PLAY RECAP ********************************************************************************************************************************************************************************************************
serverb.lab.example.com : ok=1 changed=0 unreachable=0 failed=1
serverc.lab.example.com : ok=1 changed=0 unreachable=0 failed=1
[student@workstation lab-roles]$
[student@workstation lab-roles]$ vi myenv.yml
---
# defaults file for student.myenv
myenv_user: ''
[student@workstation lab-roles]$ cat myenv.yml
---
- name: setup my personal environment
hosts: all
roles:
- role: student.myenv
myenv_user: student
[student@workstation lab-roles]$ ansible-playbook myenv.yml
PLAY [setup my personal environment] ******************************************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [serverb.lab.example.com]
ok: [serverc.lab.example.com]
TASK [student.myenv : check myenv_user default] *******************************************************************************************************************************************************************
skipping: [serverb.lab.example.com]
skipping: [serverc.lab.example.com]
TASK [student.myenv : install my packages] ************************************************************************************************************************************************************************
changed: [serverc.lab.example.com] => (item=[u'git', u'tree', u'vim-enhanced'])
changed: [serverb.lab.example.com] => (item=[u'git', u'tree', u'vim-enhanced'])
TASK [student.myenv : copy placeholder profile pic] ***************************************************************************************************************************************************************
changed: [serverc.lab.example.com]
changed: [serverb.lab.example.com]
TASK [student.myenv : set an alias in '.bashrc'] ******************************************************************************************************************************************************************
changed: [serverc.lab.example.com]
changed: [serverb.lab.example.com]
TASK [student.myenv : template out mkcd function] *****************************************************************************************************************************************************************
changed: [serverb.lab.example.com]
changed: [serverc.lab.example.com]
PLAY RECAP ********************************************************************************************************************************************************************************************************
serverb.lab.example.com : ok=5 changed=4 unreachable=0 failed=0
serverc.lab.example.com : ok=5 changed=4 unreachable=0 failed=0
Add Comment