Outils pour utilisateurs

Outils du site


tech:notes_ansible

Différences

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

Lien vers cette vue comparative

Prochaine révision
Révision précédente
tech:notes_ansible [2025/03/24 15:06] – créée - modification externe 127.0.0.1tech:notes_ansible [2025/11/20 15:28] (Version actuelle) Jean-Baptiste
Ligne 11: Ligne 11:
 * https://github.com/STEAMULO * https://github.com/STEAMULO
 * http://people.redhat.com/mlessard/mtl/presentations/apr2018/AnsibleF5WorkshopVF.pdf * http://people.redhat.com/mlessard/mtl/presentations/apr2018/AnsibleF5WorkshopVF.pdf
 +* https://legacy-controller-docs.ansible.com/automation-controller/latest/html/
 +
 +Liste des modules Ansible par catégorie : https://docs.ansible.com/ansible/2.9/modules/modules_by_category.html
 +
 +Glossary
 +* https://docs.ansible.com/ansible/latest/reference_appendices/glossary.html
 +
 +Voir mode pull :
 +* https://blog.octo.com/ansible-pull-killer-feature
  
 Voir aussi : Voir aussi :
Ligne 35: Ligne 44:
 === Install avec PIP === Install avec PIP
  
-<code bash https://raw.githubusercontent.com/mrlesmithjr/ansible-samba/master/provision.sh>+ 
 +''https://raw.githubusercontent.com/mrlesmithjr/ansible-samba/master/provision.sh'' 
 +<code bash>
 #!/bin/bash #!/bin/bash
 sudo apt-get update sudo apt-get update
Ligne 44: Ligne 55:
 ansible-playbook -i "localhost," -c local /vagrant/playbook.yml ansible-playbook -i "localhost," -c local /vagrant/playbook.yml
 </code> </code>
 +
 +
 +=== Doc
 +
 +Voir ansible-doc. Exemple :
 +<code bash>
 +ansible-doc -t keyword -l
 +</code>
 +
  
 === Inventaire === Inventaire
Ligne 81: Ligne 101:
 Ou  Ou 
  
-<code ini /etc/ansible/ansible.cfg>+''/etc/ansible/ansible.cfg'' 
 +<code ini>
 [defaults] [defaults]
 host_key_checking = False host_key_checking = False
Ligne 112: Ligne 133:
 ssh-add  ssh-add 
 </code> </code>
 +
 +Exemple de conf par variables
 +<code bash>
 +export ANSIBLE_ALLOW_EMBEDDED_TEMPLATES=false
 +export ANSIBLE_NOCOWS=true
 +export BECOME_ALLOW_SAME_USER=false
 +export ANSIBLE_PRIVATE_ROLE_VARS=true
 +export ANSIBLE_DISPLAY_ARGS_TO_STDOUT=true
 +export ANSIBLE_DISPLAY_TRACEBACK=always
 +export ANSIBLE_DUPLICATE_YAML_DICT_KEY=error
 +# export ANSIBLE_ENABLE_TASK_DEBUGGER=true
 +export ANSIBLE_HOST_PATTERN_MISMATCH=error
 +export ANSIBLE_INVENTORY_ANY_UNPARSED_IS_FAILED=true
 +export ANSIBLE_INVENTORY_UNPARSED_FAILED=true
 +</code>
 +
  
 == Usage == Usage
Ligne 137: Ligne 174:
  
 Exemple 1 Exemple 1
-<code ini ansible.cfg>+ 
 +''ansible.cfg'' 
 +<code ini>
 [defaults] [defaults]
 strategy = free strategy = free
Ligne 146: Ligne 185:
 ansible -e serial_number=50  ansible -e serial_number=50 
 </code> </code>
 +
  
 == Connexions == Connexions
Ligne 197: Ligne 237:
 Ici **foo** dépend de **bar**  Ici **foo** dépend de **bar** 
  
-<code yaml roles/foo/meta/main.yml>+ 
 +''roles/foo/meta/main.yml'' 
 +<code yaml>
 --- ---
 allow_duplicates: no allow_duplicates: no
Ligne 203: Ligne 245:
 - { role: bar } - { role: bar }
 </code> </code>
 +
 +
  
 == Exemple == Exemple
Ligne 215: Ligne 259:
  
  
-<code yaml /roles/nis_client/tasks/main.yml>+''/roles/nis_client/tasks/main.yml'' 
 +<code yaml>
 --- ---
  
Ligne 222: Ligne 267:
  
  
-<code  yaml /roles/nis_client/tasks/debian.yml>+''/roles/nis_client/tasks/debian.yml'' 
 +<code  yaml>
 --- ---
   - name: Ubuntu lancer rpcbind avant NIS   - name: Ubuntu lancer rpcbind avant NIS
Ligne 237: Ligne 283:
       - restart nis       - restart nis
 </code> </code>
 +
 +
  
 === Vérifier si un paquet deb est déjà installé === Vérifier si un paquet deb est déjà installé
Ligne 264: Ligne 312:
   changed_when: my_package_check_deb.rc == 1   changed_when: my_package_check_deb.rc == 1
 </code> </code>
 +
  
 === Exemple de find shell === Exemple de find shell
Ligne 345: Ligne 394:
   when: not ansible_check_mode   when: not ansible_check_mode
 </code> </code>
 +
 +
 === Exemple module command ne lancer qu'une seule fois une commande. === Exemple module command ne lancer qu'une seule fois une commande.
  
Ligne 369: Ligne 420:
  
 Grâce à ''gather_subset'' Grâce à ''gather_subset''
-<code yaml play.yml>+ 
 +''play.yml'' 
 +<code yaml>
 - name: Test - name: Test
   hosts: all   hosts: all
Ligne 376: Ligne 429:
  
  
 +== Copie de fichiers
 +
 +Une alternative à M(copy)
 +<code yaml>
 +- name: Download file from a file path
 +  # ansible.builtin.copy:
 +  ansible.builtin.get_url:
 +    url: file:///tmp/a_file.txt
 +    dest: /tmp/afilecopy.txt
 +</code>
  
  
Ligne 402: Ligne 465:
 La solution de contournement la plus simple à mettre en place est de définir à True la variable ''ansible_shell_allow_world_readable_temp'' La solution de contournement la plus simple à mettre en place est de définir à True la variable ''ansible_shell_allow_world_readable_temp''
  
-<code yaml play1.yml>+''play1.yml'' 
 +<code yaml>
 #!/usr/bin/ansible-playbook #!/usr/bin/ansible-playbook
  
Ligne 472: Ligne 536:
 Solution  Solution 
  
-<code ini ~/.ansible.cfg>+''~/.ansible.cfg'' 
 +<code ini>
 [defaults] [defaults]
 allow_world_readable_tmpfiles = true allow_world_readable_tmpfiles = true
Ligne 515: Ligne 580:
         rsync_path: /usr/bin/rsync         rsync_path: /usr/bin/rsync
 </code> </code>
 +
  
 === Pb No module named 'ansible' === Pb No module named 'ansible'
Ligne 525: Ligne 591:
 ModuleNotFoundError: No module named 'ansible' ModuleNotFoundError: No module named 'ansible'
 </code> </code>
 +
  
 ==== Solution ==== Solution
Ligne 534: Ligne 601:
  
 Solution si test OK Solution si test OK
-<code bash ~/.bashrc>+ 
 +''~/.bashrc'' 
 +<code bash>
 # Fix bug Ansible : No module named 'ansible' # Fix bug Ansible : No module named 'ansible'
 export PYTHONPATH=$PYTHONPATH:/usr/lib/python3/dist-packages export PYTHONPATH=$PYTHONPATH:/usr/lib/python3/dist-packages
Ligne 546: Ligne 615:
 fatal: [localhost]: FAILED! => {"msg": "The conditional check 'stat_resolv_conf.stat.attr_flags | search(\"i\")' failed. The error was: template error while templating string: Could not load \"search\": 'search'. String: {% if stat_resolv_conf.stat.attr_flags | search(\"i\") %} True {% else %} False {% endif %}. Could not load \"search\": 'search'\n\nThe error appears to be in '/home/jean/code/dns_update_resolv_conf/roles/dns_update_resolv_conf/tasks/main.yml': line 147, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Remove immutable attribute\n  ^ here\n"} fatal: [localhost]: FAILED! => {"msg": "The conditional check 'stat_resolv_conf.stat.attr_flags | search(\"i\")' failed. The error was: template error while templating string: Could not load \"search\": 'search'. String: {% if stat_resolv_conf.stat.attr_flags | search(\"i\") %} True {% else %} False {% endif %}. Could not load \"search\": 'search'\n\nThe error appears to be in '/home/jean/code/dns_update_resolv_conf/roles/dns_update_resolv_conf/tasks/main.yml': line 147, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Remove immutable attribute\n  ^ here\n"}
 </code> </code>
 +
  
 ==== Solution ==== Solution
Ligne 597: Ligne 667:
 * bats * bats
 * [[https://blog.stephane-robert.info/post/test-role-ansible-kitchenci-serverspec/|Test Kitchen]] * [[https://blog.stephane-robert.info/post/test-role-ansible-kitchenci-serverspec/|Test Kitchen]]
 +* https://docs.openstack.org/openstack-ansible/latest/contributors/testing.html
 +
 +<code bash>
 +ansible-test sanity --list-tests
 +ansible-test sanity --docker
 +</code>
  
  
Ligne 623: Ligne 699:
  
 Voir : Voir :
 + * https://ansible.readthedocs.io/projects/lint/configuring/#specifying-configuration-files
  * [[https://github.com/willthames/ansible-lint|Ansible-lint un vérificateur de syntaxe yaml playbook / rôle]]  * [[https://github.com/willthames/ansible-lint|Ansible-lint un vérificateur de syntaxe yaml playbook / rôle]]
  
-<code python .ansible-lint>+''.ansible-lint'' 
 +<code yaml>
 --- ---
  
Ligne 633: Ligne 711:
 </code> </code>
  
 +<code yaml>
 +---
 +# Offline mode disables installation of requirements.yml and schema refreshing
 +offline: true
 +
 +profile: production
 +exclude_paths:
 +  - .git/
 +  - .github/
 +  - .gitlab/
 +  - .cache/
 +warn_list:
 +  - var_naming
 +  - idiom
 +skip_list:
 +  - var-naming[no-role-prefix]
 +</code>
 +
 +
 +''.ansible-lint-ignore''
 +<code python>
 +roles/agent/defaults/main.yml var-naming[no-role-prefix]
 +</code>
  
  
Ligne 646: Ligne 747:
  
 https://beingasysadmin.wordpress.com/2015/06/03/ping-your-ansible-from-slack/ https://beingasysadmin.wordpress.com/2015/06/03/ping-your-ansible-from-slack/
 +
  
 == Autres == Autres
tech/notes_ansible.1742825205.txt.gz · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki