AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / server / Perguntas / 974203
Accepted
Mat
Mat
Asked: 2019-07-07 07:38:07 +0800 CST2019-07-07 07:38:07 +0800 CST 2019-07-07 07:38:07 +0800 CST

Tags não aplicadas na função incluída no Ansible

  • 772

Eu criei um playbook simples do Ansible:

---
- hosts: all

  tasks:
    - name: Install Icinga2 on Windows
      include_role:
        name: my.icinga2.role
        apply:
          tags:
            - install-icinga2

A função contém este arquivo de tarefas:

---
- include_tasks: vars.yml
  tags: ['always']

- include_tasks: install.yml
  tags: ['install-icinga2-stack', 'install-icinga2']

- include_tasks: ido-install.yml
  when: icinga2_ido_enable == true
  tags: ['install-icinga2-stack', 'install-icinga2-ido']  

- include_tasks: configure.yml
  tags: ['install-icinga2-stack']

[...]

Este é o resultado quando executo o playbook:

me@ansible:~/ansible$ ansible-playbook plays/icinga2-client-win.yml -i staging.ini --limit windows


PLAY [all] ***************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************
ok: [my.windows.client]

TASK [Include variables for Icinga 2] ********************************************************************************************
ok: [my.windows.client]

TASK [set_fact] ******************************************************************************************************************
skipping: [my.windows.client]

TASK [set_fact] ******************************************************************************************************************
ok: [my.windows.client]

TASK [Install Icinga2 Client and connect it to the master server] ****************************************************************

TASK [my.icinga2.role : include_tasks] ***************************************************************************************
included: /home/me/ansible/roles/internal/my.icinga2.role/tasks/vars.yml for my.windows.client

TASK [my.icinga2.role : Set default fact for mysql command] ******************************************************************
ok: [my.windows.client]

TASK [my.icinga2.role : Set fact for mysql command if auth params are given] *************************************************
skipping: [my.windows.client]

TASK [my.icinga2.role : Set Monitoring Plugins for old Debian Versions] ******************************************************
skipping: [my.windows.client]

TASK [my.icinga2.role : include_tasks] ***************************************************************************************
included: /home/me/ansible/roles/internal/my.icinga2.role/tasks/install.yml for my.windows.client

TASK [my.icinga2.role : include_tasks] ***************************************************************************************
skipping: [my.windows.client]

TASK [my.icinga2.role : include_tasks] ***************************************************************************************
skipping: [my.windows.client]

TASK [my.icinga2.role : include_tasks] ***************************************************************************************
included: /home/me/ansible/roles/internal/my.icinga2.role/tasks/install-Windows.yml for my.windows.client

TASK [my.icinga2.role : set_fact] ********************************************************************************************
ok: [my.windows.client]

TASK [my.icinga2.role : set_fact] ********************************************************************************************
skipping: [my.windows.client]

TASK [my.icinga2.role : Install Icinga 2] ************************************************************************************
changed: [my.windows.client]

TASK [my.icinga2.role : include_tasks] ***************************************************************************************
skipping: [my.windows.client]

TASK [my.icinga2.role : include_tasks] ***************************************************************************************
included: /home/me/ansible/roles/internal/my.icinga2.role/tasks/configure.yml for my.windows.client

TASK [my.icinga2.role : Check if Icinga 2 API are already activated] *********************************************************
[ This should not be included! ]

RUNNING HANDLER [my.icinga2.role : Restart Icinga2 on Windows] ***************************************************************
    to retry, use: --limit @/home/me/ansible/plays/icinga2-client-win.retry

PLAY RECAP ***********************************************************************************************************************
my.windows.client   : ok=10   changed=1    unreachable=0    failed=1 

Por que o arquivo de tarefa de função configure.yml está incluído, pois deve ser incluído somente se eu aplicar a tag install-icinga2-stack e estiver aplicando a tag install-icinga2 ?

Além disso, percebo que o arquivo de tarefa de função ido-install.yml não está incluído apenas porque a variável icinga2_ido_enabletrue não está neste playbook (e seu padrão é false), não porque uma de suas tags não é aplicada (que deve ser o que eu quero) .

Onde estou errado?

ansible
  • 1 1 respostas
  • 9285 Views

1 respostas

  • Voted
  1. Best Answer
    Vladimir Botka
    2019-07-07T12:45:31+08:002019-07-07T12:45:31+08:00

    A aplicação de tags em include_role significa que as tags

    será aplicado às tarefas dentro do include.

    Em outras palavras, as tarefas na função incluída herdarão as tags aplicadas. É um mal-entendido esperar que as tags aplicadas selecionem as tarefas. Para selecionar as tarefas, use --tagse --skip-tagsna linha de comando ou nas definições de configuração do Ansible, use as opções TAGS_RUNe TAGS_SKIP.

    Um fato importante não é mencionado explicitamente na documentação de include_role . O parâmetro apply tags funciona apenas se toda a tarefa for tags: always. Isso é mostrado apenas nos exemplos .

        - name: Apply tags to tasks within included file
          include_role:
            name: install
            apply:
              tags:
                - install
          tags:
            - always
    

    Exemplo

    Vamos ter role1 com as 2 tarefas

        shell> cat roles/role1/tasks/main.yml 
        - debug:
            msg: 'This is task 2'
          tags: task2
        
        - debug:
            msg: 'This is task 3'
          tags: task3
    

    e uma cartilha

        shell> cat play1.yml 
        - hosts: localhost
          tasks:
            - debug:
                msg: 'This is task 1'
              tags: task1
    
            - include_role:
                name: role1
                apply:
                  tags: role1
              tags: always
    

    Se executarmos o playbook sem nenhuma opção, todas as tarefas serão incluídas

        shell> ansible-playbook play1.yml | grep msg
            "msg": "This is task 1"
            "msg": "This is task 2"
            "msg": "This is task 3"
    

    Veja outras variações abaixo

        shell> ansible-playbook play1.yml --tags task1 | grep msg
            "msg": "This is task 1"
        shell> ansible-playbook play1.yml --tags task2 | grep msg
            "msg": "This is task 2"
        shell> ansible-playbook play1.yml --tags role1 | grep msg
            "msg": "This is task 2"
            "msg": "This is task 3"
        shell> ansible-playbook play1.yml --skip-tags role1 | grep msg
            "msg": "This is task 1"
        shell> ansible-playbook play1.yml --tags role1 --skip-tags task2 | grep msg
            "msg": "This is task 3"
    

    Nota . A listagem de tags não funciona como esperado.

        shell> ansible-playbook play1.yml --list-tags
        playbook: play1.yml
          play #1 (localhost): localhost    TAGS: []
              TASK TAGS: [always, task1]
    

    (Para o registro: include_role com as tags de aplicação não funciona #52063 )

    • 7

relate perguntas

  • Tarefas Ansible Recorrentes

  • Não é possível formar um link de um arquivo que está em sites disponíveis para um diretório habilitado para sites no servidor remoto usando ansible?

  • como executar um determinado papel do ansible?

  • Ansible e rbash

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Você pode passar usuário/passar para autenticação básica HTTP em parâmetros de URL?

    • 5 respostas
  • Marko Smith

    Ping uma porta específica

    • 18 respostas
  • Marko Smith

    Verifique se a porta está aberta ou fechada em um servidor Linux?

    • 7 respostas
  • Marko Smith

    Como automatizar o login SSH com senha?

    • 10 respostas
  • Marko Smith

    Como posso dizer ao Git para Windows onde encontrar minha chave RSA privada?

    • 30 respostas
  • Marko Smith

    Qual é o nome de usuário/senha de superusuário padrão para postgres após uma nova instalação?

    • 5 respostas
  • Marko Smith

    Qual porta o SFTP usa?

    • 6 respostas
  • Marko Smith

    Linha de comando para listar usuários em um grupo do Windows Active Directory?

    • 9 respostas
  • Marko Smith

    O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL?

    • 3 respostas
  • Marko Smith

    Como determinar se uma variável bash está vazia?

    • 15 respostas
  • Martin Hope
    Davie Ping uma porta específica 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    kernel O scp pode copiar diretórios recursivamente? 2011-04-29 20:24:45 +0800 CST
  • Martin Hope
    Robert ssh retorna "Proprietário incorreto ou permissões em ~/.ssh/config" 2011-03-30 10:15:48 +0800 CST
  • Martin Hope
    Eonil Como automatizar o login SSH com senha? 2011-03-02 03:07:12 +0800 CST
  • Martin Hope
    gunwin Como lidar com um servidor comprometido? 2011-01-03 13:31:27 +0800 CST
  • Martin Hope
    Tom Feiner Como posso classificar a saída du -h por tamanho 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent Como determinar se uma variável bash está vazia? 2009-05-13 09:54:48 +0800 CST

Hot tag

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve