Leń¶

Z Mariana trochę jest leń więc często dodaje aliasy od basha. Dlatego g to git, co bardzo często irytuje innych. Jednak Marian jest pod to.
Rola: Bashrc¶
roles/
bashrc/
tasks/
main.yml
files/
main.yml
Files¶
#MY ALIASES
alias tmrun='tmuxinator start $1'
alias pb='pybot -v ENV_NAME:$1 --loglevel DEBUG $2'
alias g='git'
Tasks¶
---
- name: create config directory
file:
path: "{{ user_config }}"
state: directory
owner: root
group: root
mode: 0755
register: config
tags:
- config
- name: create config directory
file:
path: "{{ user_config }}"
state: directory
owner: root
group: root
mode: 0755
register: config
tags:
- config
- name: create aliases file
copy:
dest: "{{ user_config }}/aliases.sh"
src: aliases.sh
- name: check aliases in bashrc user
shell: "grep '^source {{ user_config }}/aliases.sh' {{ home_path }}/.bashrc | cat"
register: grep_aliases_user
- name: add aliases to bashrc user
lineinfile:
path: "{{ home_path }}/.bashrc"
line: "source {{ user_config }}/aliases.sh"
state: present
when: grep_aliases_user.stdout == ""
- name: check aliases in bashrc root
shell: "grep '^source {{ user_config }}/aliases.sh' /root/.bashrc | cat"
register: grep_aliases_root
- name: add aliases to bashrc root
lineinfile:
path: "/root/.bashrc"
line: "source {{ user_config }}/aliases.sh"
state: present
when: grep_aliases_root.stdout == ""
Output¶
$ ansible-playbook playbooks/bashrc.yml
PLAY [create config place] ***************************************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************************************
ok: [localhost]
TASK [bashrc : create config directory] **************************************************************************************************************
ok: [localhost]
TASK [bashrc : create aliases file] ******************************************************************************************************************
changed: [localhost]
TASK [bashrc : check aliases in bashrc user] *********************************************************************************************************
changed: [localhost]
TASK [bashrc : add aliases to bashrc user] ***********************************************************************************************************
skipping: [localhost]
TASK [bashrc : check aliases in bashrc root] *********************************************************************************************************
changed: [localhost]
TASK [bashrc : add aliases to bashrc root] ***********************************************************************************************************
skipping: [localhost]
PLAY RECAP *******************************************************************************************************************************************
localhost : ok=5 changed=3 unreachable=0 failed=0
Note
Shell pozwala wykonywanie dowolnej komendy w shellu, na przykład grep itp. Za pomocą register możemy przechwycić stdout i używać w When dla kolejnego zadania. Shell