Outils pour utilisateurs

Outils du site


tech:ansible_-_exemples

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
tech:ansible_-_exemples [2025/04/24 12:57] Jean-Baptistetech:ansible_-_exemples [2025/12/04 11:13] (Version actuelle) Jean-Baptiste
Ligne 1: Ligne 1:
 +<!DOCTYPE markdown>
 +{{tag>Brouillon CA}}
 +
 +# Ansible - exemples
 +
 +~~~yaml
 +- name: install truc
 +  import_tasks: "1-install-truc.yml"
 +
 +- name: conf truc
 +  import_tasks: "2-conf-truc.yml"
 +
 +- name: install plop
 +  import_tasks: "3-install-plop.yml"
 +~~~
 +
 +É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: /bin/false
 +
 +    - 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: /bin/false
 +
 +    - 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('pipe', 'date') }}
 +
 +- name: create a mysql user with a random password using many different char sets
 +  mysql_user:
 +    name: "{{ client }}"
 +    password" "{{ lookup('password', '/tmp/passwordfile chars=ascii_letters,digits,hexdigits,punctuation') }}"
 +    priv: "{{ client }}_{{ tier }}_{{ role }}.*:ALL"
 +
 +~~~
 +
 +
 +
 +
 +## Exemple config projet
 +
 +''.ansible-lint''
 +
 +~~~yaml
 +---
 +skip_list:
 +- '303'  # Using command rather than module for yum/dnf
 +- ignore-errors
 +~~~
 +
 +''.yamllint.yml''
 +~~~yaml
 +# SPDX-License-Identifier: MIT
 +---
 +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, then
 +# 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: |
 +#   /tests/
 +#   /.tox/
 +# 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
 +~~~
 +
 +''.yamllint_defaults.yml''
 +~~~yaml
 +# SPDX-License-Identifier: MIT
 +---
 +ignore: |
 +  /.tox/
 +extends: default
 +rules:
 +  braces:
 +    max-spaces-inside: 1
 +    level: error
 +  brackets:
 +    max-spaces-inside: 1
 +    level: error
 +  truthy:
 +    allowed-values: ["yes", "no", "true", "false"]
 +    level: error
 +  document-start: disable
 +  colons: disable
 +~~~
 +
 +
 +.yamllint
 +
 +
 +~~~yaml
 +extends: default
 +
 +rules:
 +  colons:
 +    max-spaces-before: 1
 +    max-spaces-after: 20
 +  line-length: disable
 +~~~
 +
 +---
 +
 +''ansible.cfg''
 +~~~ini
 +[defaults]
 +roles_path = ../
 +
 +~~~
 +
 +~~~bash
 +# To generate an example config file (a "disabled" one with all default settings, commented out):
 +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 ''ansible-navigator config''
 +
 +''.gitignore''
 +~~~
 +*.retry
 +/.vagrant
 +*.swp
 +~~~
 +
 +
 +
 +
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki