====== DevOps - Ansible ======
* layout: http://docs.ansible.com/ansible/playbooks_best_practices.html
* network: https://raymii.org/s/tutorials/KVM_with_bonding_and_VLAN_tagging_setup_on_Ubuntu_12.04.html
====== Ansible ======
* develop module: http://docs.ansible.com/ansible/developing_modules.html
* http://blog.toast38coza.me/custom-ansible-module-hello-world/
* https://www.digitalocean.com/community/tutorials/how-to-configure-apache-using-ansible-on-ubuntu-14-04
====== Ansible kvm ======
* https://raymii.org/s/tutorials/KVM_with_bonding_and_VLAN_tagging_setup_on_Ubuntu_12.04.html
* https://github.com/bennojoy/ansible-roles/tree/master/network
* http://docs.openstack.org/developer/openstack-ansible/mitaka/install-guide/configure-networking.html
* Networking:
* http://www.linux-kvm.org/page/Networking
====== Ansible OpenStack ======
* http://www.jinkit.com/openstack-ansible/
* https://cunninghamshane.com/openstack-in-containers-install-and-upgrade/
====== Ansible tips ======
* Best practices: http://docs.ansible.com/ansible/playbooks_best_practices.html#directory-layout
* Develope module: http://docs.ansible.com/ansible/developing_modules.html
* ansible-galaxy: requirements.yml http://stackoverflow.com/questions/25230376/how-to-automatically-install-ansible-galaxy-roles
* http://stackoverflow.com/questions/33857134/checking-for-multiple-conditions-using-when-on-single-task-in-ansible
* http://stackoverflow.com/questions/22758925/abort-execution-of-remaining-task-if-certain-condition-is-failed
* http://stackoverflow.com/questions/26188055/ansible-understanding-a-compound-conditional-when-statement
* tap tun: https://mail.gnome.org/archives/networkmanager-list/2016-January/msg00053.html
===== Role and library =====
* Ansible module is a .py file implementing the module. It must be placed in playbook_dir/library, or playbook_dir/roles/role_name/library, or in a directory specified in "library=" in ansible.cfg
* There is currently no way to pull module from git and place in library folders. This is useful when i.e., forking available module for development. However, ansible-galaxy enables installation of roles from git, etcs. One way that make sense is to fork the module and turn it into role, which can be installed by ansible-galaxy in requirements.yml file.
* http://stackoverflow.com/questions/34918058/using-ansible-modules-from-git-repository
* http://stackoverflow.com/questions/34901858/how-to-keep-local-roles-separated-from-the-ones-loaded-from-ansible-galaxy/34902605#34902605
How to do that?:
Clone a module e.g., nmcli, and copy meta/main.yml to make it a role :-):
tree library_ext/ansible-nmcli-b3936faaedd4c0ab7f091806460253eff508e816
library_ext/ansible-nmcli-b3936faaedd4c0ab7f091806460253eff508e816
├── library
│ └── nmcli_dev.py
├── meta
│ └── main.yml
├── playbook-add.yml
├── playbook-del.yml
├── README.md
└── testing_scripts
├── add-connection.py
├── list-connections.py
├── list-con-simple.py
├── list-devices.py
├── test-dbus.py
└── timetest.py
Now it can be installed by ansible-galaxy in to library_ext folder:
# cat requirements.yml
---
- src: https://github.com/thuydang/ansible_nmcli_role.git
path: ./library_ext/
# vim ansible.cfg so moudles in subdir are searched for by ansible
# the trick is putting library in the path. This should be supported by default but is currently a bug:
library = /usr/share/ansible:library_ext:library #https://github.com/ansible/ansible/issues/16561#issuecomment-230146841
# vim ansible.cfg to add library_ext to list of roles folders
roles_path = library_ext:roles_ext
# install the role (library) with ansible-galaxy
[dang@dai142 ansible_quicklabs]$ ansible-galaxy install -r requirements.yml
- extracting ansible_nmcli_role to /mnt/nfv/ansible_quicklabs_ws/ansible_quicklabs/library_ext/ansible_nmcli_role
- ansible_nmcli_role was installed successfully
** copy meta to make it detected as a role **
===== Nested list in yaml variables =====
* http://stackoverflow.com/questions/30869519/how-to-traverse-a-nested-dict-structure-with-ansible
====== Ansible Debug ======
Step: Enable debug
[dang@dai142 ansible]$ cat vfoss_dev_postgres_setup_playbook.yml
---
- name: Install and configure postgresql replica sets
strategy: debug <---------------- this is it
hosts: vfoss_dev
become: true
remote_user: root
vars_files:
- 'vars/vars_vfoss_dev.yml'
roles:
- { role: ansible-role-postgresql }
Step: Make it failed then the debug will kickin
[dang@dai142 ansible]$ cat roles/ansible-role-postgresql/tasks/main.yml
---
- name: Installing postgresql
include: 'install.yml'
- debug: msg={{ postgresql_data_dir }}
- debug: var={{ postgresql_master }}
- name: DEBUG postgresql_master <------------------- this is it
fail: msg="debug"
when: (postgresql_master is undefined) or (not postgresql_master|bool) #or true
#when: not postgresql_master|bool
- name: Configuring the master
include: 'configure-master.yml'
when: postgresql_master
Step: Playbook Debuger console
* https://docs.ansible.com/ansible/playbooks_debugger.html
p task/vars/host/result : Print values used to execute a module:
task.args[key] = value : Update module’s argument.
task.args['name'] = 'bash'
vars[key] = value : Update vars.
vars['pkg_name'] = 'bash'
(debug) vars['postgresql_streaming_slaves'] = []
(debug) r
r(edo)
Run the task again. c(ontinue)
Just continue. q(uit)
====== Ansibletools ======
yaml-online-parser.appspot.com