- install python
- install ansible
on MacOS you might need to install pip
via
sudo easy_install pip
make sure Ansible version is above of 2.5.0
- install bob & bob3.
pip install boto
pip install boto3
ansible-galaxy install -r requirements.yml
- create ansible_{env}.cfg
[defaults]
inventory = ~/devops/ansible/{env}
host_key_checking = False
vault_password_file = ~/ansible/vault_{env}_pass
remote_user = centos
private_key_file = ~/.ssh/id_rsa
- create new iTerm2 profile with
Send text at start
setup (2 lines)
export ANSIBLE_CONFIG=~/ansible/ansible_{env}.cfg
- now you can open iTerm2 specific env profile and using
ansible
oransible-playbook
directly.
Notes: if you have ansible config with inventory setup, you can ignore -i {environment}
attribute in the following examples.
test with ansible all -m ping
and you should get the response below.
dev-e | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}
dev-a | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}
ansible-playbook -i joe setup-event-listener.yml -e "ansible_ssh_user=root"
ansible-playbook -i production setup-event-listener.yml
ansible-playbook -i joe setup-event-listener.yml -e "ansible_ssh_user=root" --skip-tags "init"
ansible-playbook -i production setup-event-listener.yml --skip-tags "init"
ansible-playbook -i dev setup.yml --tags "company-backend,brand-backend" -e "ansible_ssh_user=joecwu"
or with All-In-One env setup
ansible-playbook setup.yml --tags "company-backend,brand-backend"
ansible-playbook -i staging setup-integration-backend.yml -e "ansible_ssh_user=centos" --ask-vault-pass
ansible-playbook -i staging setup.yml -e "ansible_ssh_user=centos" --ask-vault-pass --limit ms-3
or with All-In-One env setup
ansible-playbook setup.yml --limit ms-3
ansible-vault decrypt production/group_vars/*/vault
ansible-vault encrypt production/group_vars/*/vault
fatal: [dev-apis]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to import docker-py - No module named requests.exceptions. Try `pip install docker-py`"}
this error indicate the remote client has no related python module, not local host.
For people lazy to read every post here:
Since ansible 2.3, the dependency issue docker-py is fixed:
if you use the default python 2.7, the docker module needs docker-py
if you use python 3 (-e 'ansible_python_interpreter=/usr/bin/python3' ), it needs docker instead of docker-py
in all case, clean by pip uninstall docker docker-py docker-compose
reinstall
pip install docker-compose
Solution: setup dependencies in runner machine
yum install -y epel-release
yum install -y python-pip
pip install docker-py
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "boto required for this module"}
Solution: setup boto on Control Machine
pip install boto
ref:stackoverflow
ansible all -m shell -a "df -h|grep /dev/xvd"