tech:ansible_-_exemples
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| tech:ansible_-_exemples [2025/12/04 11:10] – Jean-Baptiste | tech:ansible_-_exemples [2025/12/04 11:13] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Ansible - exemples | ||
| + | |||
| + | ~~~yaml | ||
| + | - name: install truc | ||
| + | import_tasks: | ||
| + | |||
| + | - name: conf truc | ||
| + | import_tasks: | ||
| + | |||
| + | - name: install plop | ||
| + | import_tasks: | ||
| + | ~~~ | ||
| + | |||
| + | Équivalent try except finally | ||
| + | ~~~yaml | ||
| + | - name: Attempt and graceful roll back demo | ||
| + | block: | ||
| + | - name: Print a message | ||
| + | ansible.builtin.debug: | ||
| + | msg: 'I execute normally' | ||
| + | |||
| + | - name: Force a failure | ||
| + | ansible.builtin.command: | ||
| + | |||
| + | - name: Never print this | ||
| + | ansible.builtin.debug: | ||
| + | msg: 'I never execute, due to the above task failing, :-(' | ||
| + | rescue: | ||
| + | - name: Print when errors | ||
| + | ansible.builtin.debug: | ||
| + | msg: 'I caught an error' | ||
| + | |||
| + | - name: Force a failure in middle of recovery! >:-) | ||
| + | ansible.builtin.command: | ||
| + | |||
| + | - name: Never print this | ||
| + | ansible.builtin.debug: | ||
| + | msg: 'I also never execute :-(' | ||
| + | always: | ||
| + | - name: Always do this | ||
| + | ansible.builtin.debug: | ||
| + | msg: "This always executes" | ||
| + | ~~~ | ||
| + | |||
| + | ## Plugin lookup | ||
| + | |||
| + | ~~~yaml | ||
| + | - name: raw result of running date command" | ||
| + | debug: | ||
| + | msg: "{{ lookup(' | ||
| + | |||
| + | - name: create a mysql user with a random password using many different char sets | ||
| + | mysql_user: | ||
| + | name: "{{ client }}" | ||
| + | password" | ||
| + | priv: "{{ client }}_{{ tier }}_{{ role }}.*: | ||
| + | |||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Exemple config projet | ||
| + | |||
| + | '' | ||
| + | |||
| + | ~~~yaml | ||
| + | --- | ||
| + | skip_list: | ||
| + | - ' | ||
| + | - ignore-errors | ||
| + | ~~~ | ||
| + | |||
| + | '' | ||
| + | ~~~yaml | ||
| + | # SPDX-License-Identifier: | ||
| + | --- | ||
| + | extends: .yamllint_defaults.yml | ||
| + | # possible customizations over the base yamllint config | ||
| + | # skip the yaml files in the /tests/ directory | ||
| + | # NOTE: If you want to customize `ignore` you'll have to | ||
| + | # copy in all of the config from .yamllint.yml, | ||
| + | # add your own - so if you want to just add /tests/ to | ||
| + | # be ignored, you'll have to add the ignores from the base | ||
| + | # ignore: | | ||
| + | # / | ||
| + | # / | ||
| + | # skip checking line length | ||
| + | # NOTE: the above does not apply to `rules` - you do not | ||
| + | # have to copy all of the rules from the base config | ||
| + | ~~~ | ||
| + | |||
| + | '' | ||
| + | ~~~yaml | ||
| + | # SPDX-License-Identifier: | ||
| + | --- | ||
| + | ignore: | | ||
| + | /.tox/ | ||
| + | extends: default | ||
| + | rules: | ||
| + | braces: | ||
| + | max-spaces-inside: | ||
| + | level: error | ||
| + | brackets: | ||
| + | max-spaces-inside: | ||
| + | level: error | ||
| + | truthy: | ||
| + | allowed-values: | ||
| + | level: error | ||
| + | document-start: | ||
| + | colons: disable | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | .yamllint | ||
| + | |||
| + | |||
| + | ~~~yaml | ||
| + | extends: default | ||
| + | |||
| + | rules: | ||
| + | colons: | ||
| + | max-spaces-before: | ||
| + | max-spaces-after: | ||
| + | line-length: | ||
| + | ~~~ | ||
| + | |||
| + | --- | ||
| + | |||
| + | '' | ||
| + | ~~~ini | ||
| + | [defaults] | ||
| + | roles_path = ../ | ||
| + | |||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | # To generate an example config file (a " | ||
| + | ansible-config init --disabled > ansible.cfg | ||
| + | |||
| + | # Also you can now have a more complete file by including existing plugins: | ||
| + | ansible-config init --disabled -t all > ansible.cfg | ||
| + | |||
| + | # Voir la configuration : | ||
| + | ansible-config dump --only-changed -t all | ||
| + | ~~~ | ||
| + | Voir '' | ||
| + | |||
| + | '' | ||
| + | ~~~ | ||
| + | *.retry | ||
| + | /.vagrant | ||
| + | *.swp | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
