Actions
Ansible cheat sheet » History » Revision 7
« Previous |
Revision 7/25
(diff)
| Next »
Jon Goldberg, 01/31/2022 08:33 PM
{{last_updated_at}} by {{last_updated_by}}
Ansible cheat sheet¶
This page will cover some helpful one-line commands we can execute with Ansible to accomplish various tasks. Always run git pull and git submodule update before executing these commands.
Synchronize a non-canonical site with the live site's database¶
ansible-playbook main-playbook.yml --tags site-db-sync -l mysite.local
- This works on test and dev sites.
- Depending on the sync strategy on the website inventory, it will pull from last night's backup, sync directly from the live site, or use the Pantheon API to make a backup/download.
- Only sites that pull from backup can sync to a site that's not on your local machine at present (I'll fix this at some point).
Ad-hoc examples¶
Revert a failed local update¶
ansible '*.local' -m shell -a "cd {{webroot}} && git checkout ." --become --become-user "{{ run_as_user }}"
Roll back a site to the latest commit (e.g. after a failed merge):¶
ansible --become -m shell -a 'cd {{civiroot}} && git clean -fdx {{civiroot}} && get reset --hard HEAD' mysite1.local,mysite2.local
Send a drush command to multiple sites¶
This is trickier to handle places where we don't have root, but works.
ansible --become --become-user="{{ run_as_user }}" -m shell -a "PATH=\$HOME/bin:\$PATH; drush --root={{ webroot }} pm-disable -y print" 'maintenance_drupal'
Send an arbitrary SQL statement to all Civi test instances with maintenance contracts¶
ansible --become --become-user="{{ run_as_user }}" -m shell -a "PATH=\$HOME/bin:\$PATH; echo \"UPDATE civicrm_job SET is_active = 0 WHERE api_action = 'group_rebuild';\" | cv --cwd={{ webroot }} sql" 'maintenance_civi:&websites_test'
Set CLI PHP version across all servers¶
This is an example of server-level changes (others are site-level).
ansible --become -m command -a 'update-alternatives --set php /usr/bin/php7.4' vps
Updated by Jon Goldberg almost 3 years ago · 7 revisions