Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
linux_wiki:ansible-pull [2018/07/20 23:31] billdozor created |
linux_wiki:ansible-pull [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 25: | Line 25: | ||
The entire role directory structure/ | The entire role directory structure/ | ||
+ | |||
+ | ===== Playbook: Directory Stucture ===== | ||
+ | |||
+ | The directory structure for an Ansible Pull repo does not look that much different than Ansible' | ||
+ | |||
+ | If this method is followed, the same role can also be used on the system that does regular ansible-playbook push commands (referenced from a different playbook file). | ||
+ | |||
+ | <code bash> | ||
+ | ├── myplaybook.yml | ||
+ | └── myrole | ||
+ | ├── files | ||
+ | ├── handlers | ||
+ | │ └── main.yml | ||
+ | ├── tasks | ||
+ | │ └── main.yml | ||
+ | └── vars | ||
+ | └── main.yml | ||
+ | </ | ||
+ | |||
+ | ---- | ||
===== Playbook: Example ===== | ===== Playbook: Example ===== | ||
Example of a playbook tailored for pulling. | Example of a playbook tailored for pulling. | ||
- | < | + | < |
+ | # File: myplaybook.yml | ||
+ | # Description: | ||
+ | |||
+ | # hosts to run on | ||
+ | - hosts: | ||
+ | - localhost | ||
+ | |||
+ | # roles: located in same directory | ||
+ | roles: | ||
+ | # role: role to assign to hosts, tags: tag(s) to give entire role | ||
+ | - { role: myrole, tags: myrole } | ||
+ | |||
+ | # Do not gather host facts for this playbook (comment out/remove if you need facts) | ||
+ | gather_facts: | ||
</ | </ | ||
Line 35: | Line 69: | ||
Example of a role that can be used with either a pull playbook or normal playbook. | Example of a role that can be used with either a pull playbook or normal playbook. | ||
- | < | + | |
+ | \\ | ||
+ | File: myrole/ | ||
+ | <code yaml> | ||
+ | - name: Install my awesome app list | ||
+ | yum: | ||
+ | name: "{{ my_awesome_apps }}" | ||
+ | state: present | ||
+ | notify: restart my awesome service | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | File: myrole/ | ||
+ | <code yaml> | ||
+ | my_awesome_apps: | ||
+ | - myapp1 | ||
+ | - myapp2 | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | File: myrole/ | ||
+ | < | ||
+ | - name: restart my awesome service | ||
+ | service: | ||
+ | name: my-awesome-service | ||
+ | state: restarted | ||
+ | </ | ||
---- | ---- | ||
====== The Client: Putting It All Together ====== | ====== The Client: Putting It All Together ====== | ||
+ | |||
+ | Steps for the client to run the playbook via ansible-pull. | ||
+ | |||
+ | Example with a git repo | ||
+ | * Install ansible and git<code bash>yum -y install ansible git</ | ||
+ | |||
+ | * **If Using SSH Key Login** | ||
+ | * Copy private ssh key to root's .ssh directory< | ||
+ | * Ensure proper permissions< | ||
+ | chmod 600 / | ||
+ | |||
+ | * Create a directory for ansible-pull to clone into< | ||
+ | |||
+ | * Run the ansible-pull command | ||
+ | * **SSH Key Example**< | ||
+ | * **HTTPS Example**< | ||
+ | |||
+ | Options Used | ||
+ | * --directory | ||
+ | * --url -> SSH or HTTPS url to clone from | ||
+ | * --key-file | ||
+ | * --accept-host-key | ||
+ | * --clean | ||
+ | * myplaybook.yml | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== Beyond: Continuous Deployment ====== | ||
+ | |||
+ | Using ansible-pull, | ||
+ | |||
+ | Automation Ideas | ||
+ | * Create a cron that runs an ansible-pull script | ||
+ | * The script could provide logging for ansible-pull command output | ||
+ | * Have the cron run frequently enough to pick up changes fast (every 15 minutes or so) | ||
+ | |||
+ | * Add an argument to the ansible-pull command to only execute if the remote repo has been updated< | ||
+ | |||
+ | * Create a branch for each type of environment systems are in. | ||
+ | * Examples: | ||
+ | * Unstable | ||
+ | * Development | ||
+ | * Testing | ||
+ | * Production | ||
+ | * Add protection to Development, | ||
+ | * Use Unstable to test changes to a small group of systems | ||
+ | |||
+ | * Add an argument to the ansible-pull command to include the branch name for each environment. Development branch example< | ||
---- | ---- | ||