Системные модули и скрипты
Установка и/или проверка установки apt пакета
Название модуля: apt
Переменные:
- name: ntp #имя проверяемого и устанавливаемого модуля
- state: present #состояние после завершения
- update_cache: yes # обновлять ли кэш
- name: Install module
  apt: 
    name: ntp
    state: present
    update_cache: yes
Добавить ключ стороннего репозитория
- name: Add Docker GPG key
  apt_key:
     url: https://download.docker.com/linux/ubuntu/gpg
Добавить сторонний репозиторий
- name: Add Docker repository
  apt_repository:
    repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stableОбновить apt кэш
- name: Update apt cache
  apt: update_cache=yesКопирование файлов
Копирование с локального на удаленный
- name: Copy from server to client
  copy:
    src: /home/user/file.txt 
    dest: /home/setup/file.txt
    owner: foo
    group: foo
    mode: '0644'Копирование с удаленного на локальный
- name: Copy from client to server
  fetch:
    src: /var/log/access.log
    dest: /var/log/fetched
    flat: true удалить структуру родительских папок для файлаСоздание пользователя и группы
Создание пользователя
- name: Create and/or check presence user
  user:
    name: install
    state: present
    shell: /bin/bash
    group: sudo
    system: yes
    hidden: yes
    ssh_key_file: .ssh/id_rsa
    expires: -1Создание группы
- name: Create check group
  group:
    name: clustergroup
    state: present
    gid: 1040Управление сервисами (daemon)
- name: Update sysctl
  sysctl:
    name: net.ipv4.ip_forward
    value: 1
    sysctrl_set: yes
    state: present
    reload: yes   - name: Set or check service
  service:
    name: ntp
    state: started
    enabled: yes- name: Set check daemon starting
  systemd:
    name: ntp
    state: started
    enabled: yes
    masked: no
    daemon_reload: yes
    register: systemdcron:
Скрипты и консольные команды
- name: Raw command
  raw: echo "this was written by a raw Ansible module!!" >> ~/raw.txt- name: Executing script
  shell: ./shell_script.sh >> ~/shell.txt
    args:
    chdir: /usr/local/
    creates: ~/shell.txt
    executable: /bin/csh- name: Executing python script
  script: ./shell_script.py –some-argumets "42"
    args:
    creates: ~/shell.txt
    executable: pythonДля исполнения expect скриптов нужно сначала проверить и установить пакет expect
- name: Expect module
  expect:
    command: passwd user1
    responses:
    (?i)password: "Ju5tAn07herP@55w0rd": 
                
No comments to display
No comments to display