devops:ansible
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| devops:ansible [2018/03/19 15:43] – [Remove Old SSH Key Fingerprint] skipidar | devops:ansible [2023/11/01 07:15] (current) – ↷ Page moved from camunda:devops:ansible to devops:ansible skipidar | ||
|---|---|---|---|
| Line 182: | Line 182: | ||
| < | < | ||
| sed -i ' | sed -i ' | ||
| - | sed -i 's/.*pipelining.*/ | + | sed -i 's/.*allow_world_readable_tmpfiles |
| </ | </ | ||
| Line 222: | Line 222: | ||
| - | ==== Extra vars ==== | + | ==== Extra vars alias arguments |
| - | Pass external variables to the playbook, to e.g. define hosts outside of the playbook. | + | Pass external variables |
| < | < | ||
| Line 239: | Line 239: | ||
| ... | ... | ||
| </ | </ | ||
| + | |||
| + | |||
| + | |||
| + | ==== Ansible behind proxy ==== | ||
| + | |||
| + | If you configure the Hosts to use corkscrew, then ansible will be able to reach the machines: | ||
| + | |||
| + | Open / | ||
| + | < | ||
| + | Host * | ||
| + | ProxyCommand corkscrew 194.138.0.33 9400 %h %p | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ==== Galaxy ==== | ||
| + | You can use the galaxy (https:// | ||
| + | |||
| + | A role " | ||
| + | < | ||
| + | ansible-galaxy install cmacrae.sensu | ||
| + | </ | ||
| + | |||
| + | After that you can embed the role into your playbooks: | ||
| + | |||
| + | < | ||
| + | --- | ||
| + | - name: Install sensu | ||
| + | hosts: slave | ||
| + | become: true | ||
| + | roles: | ||
| + | - { role: cmacrae.sensu, | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== MODULE FAILURE - rc 127 ==== | ||
| + | |||
| + | When ssh works, but the ping fails with | ||
| + | < | ||
| + | $ ansible slaves -m ping -vvvv | ||
| + | |||
| + | ansible 2.5.0 | ||
| + | config file = / | ||
| + | configured module search path = [u'/ | ||
| + | ansible python module location = / | ||
| + | executable location = / | ||
| + | python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Then it will help to ssh to the remote host and install python | ||
| + | < | ||
| + | ssh 34.242.178.166 -l ubuntu -i / | ||
| + | ubuntu@34.242.178.166: | ||
| + | </ | ||
| + | |||
| + | Check https:// | ||
| + | |||
| + | |||
| + | ==== AWX installation ==== | ||
| + | The UI, which enables team management and delegation is available as the AWX project | ||
| + | https:// | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ==== Importing and Including ==== | ||
| + | |||
| + | |include*|Is done evaluated at runtime| | ||
| + | |Import*|Is done at compile time. PREFER THAT.| | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | === import_tasks === | ||
| + | Can be used, to extract equal steps you want to reuse in a separate file. | ||
| + | |||
| + | |import_tasks*| Allows passing variables. Requires the imported file to have only tasks, no " | ||
| + | |||
| + | |||
| + | Usecase: requirements for a Renderer/ | ||
| + | |||
| + | common_requirements.yaml | ||
| + | It is important, that you dont have the header here. Only tasks | ||
| + | < | ||
| + | |||
| + | - name: Creates product configuration file | ||
| + | file: | ||
| + | path: / | ||
| + | state: touch | ||
| + | owner: ubuntu | ||
| + | group: ubuntu | ||
| + | mode: 0700 | ||
| + | |||
| + | - name: product config content | ||
| + | copy: | ||
| + | dest: "/ | ||
| + | content: | | ||
| + | Acquire:: | ||
| + | Verify-Peer " | ||
| + | Verify-Host " | ||
| + | |||
| + | SslCert "/ | ||
| + | SslKey "/ | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | Renderer: | ||
| + | < | ||
| + | --- | ||
| + | - hosts: "{{ host }}" | ||
| + | become: true | ||
| + | become_method: | ||
| + | become_user: | ||
| + | tasks: | ||
| + | |||
| + | - name: Install product requirements | ||
| + | import_tasks: | ||
| + | vars: | ||
| + | host: aws | ||
| + | |||
| + | - name: Install renderer | ||
| + | become: true | ||
| + | apt: product_renderer | ||
| + | </ | ||
| + | |||
| + | Viewer: | ||
| + | < | ||
| + | --- | ||
| + | - hosts: "{{ host }}" | ||
| + | become: true | ||
| + | become_method: | ||
| + | become_user: | ||
| + | tasks: | ||
| + | |||
| + | - name: Install product requirements | ||
| + | import_tasks: | ||
| + | vars: | ||
| + | host: aws | ||
| + | |||
| + | - name: Install VIEWER, reusing the tasks | ||
| + | become: true | ||
| + | apt: product_viewer | ||
| + | </ | ||
| + | |||
| + | |||
| + | === import_playbook === | ||
| + | |||
| + | Unfortunately lacks the possibility to pass in variables. | ||
| + | Which makes it unusable | ||
| + | |||
| + | |||
| + | |||
| + | ==== Read remote files ==== | ||
| + | To read remote file do use slurp | ||
| + | |||
| + | |||
| + | < | ||
| + | - name: set facts | ||
| + | set_fact: | ||
| + | dest_timestamp: | ||
| + | | ||
| + | | ||
| + | - name: Slurp timestamp file | ||
| + | slurp: | ||
| + | src: "{{ dest_timestamp }}" | ||
| + | register: slurpfile | ||
| + | |||
| + | - name: set the timestamp fact | ||
| + | set_fact: | ||
| + | timestamp: "{{ slurpfile[' | ||
| + | |||
| + | - name: timestamp variable | ||
| + | debug: msg=" | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Execute a shell script, as a user with a valid environment ==== | ||
| + | Sometimes you face the issues, that the environment variables defined by some tool, installed for a special user - are not defined, when you execute the tool. | ||
| + | |||
| + | To execute some installed software in a valid environment, | ||
| + | with / | ||
| + | with / | ||
| + | etc | ||
| + | |||
| + | use the following approach. | ||
| + | |||
| + | < | ||
| + | # unfortunately the environment defined by tool in / | ||
| + | - name: processing step | ||
| + | shell: | ||
| + | sudo -iu ubuntu yourtool.sh | ||
| + | args: | ||
| + | executable: /bin/bash | ||
| + | |||
| + | |||
| + | -i [command] | ||
| + | The -i (simulate initial login) option runs the shell specified in the passwd(5) entry of the target user as a login shell. | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | </ | ||
| + | See https:// | ||
| + | |||
| + | UNfortunately the aproach with become_user - does not have the same result | ||
| + | |||
| + | |||
devops/ansible.1521474181.txt.gz · Last modified: (external edit)
