2
respostas

Erro ao executar o ansible para criar o arquivo na EC2

Bom dia! Tudo bem?!

Estou com um problemas ao tenatr executar o ansible. Se gue erro e o arquivo playbook.yml

###################################################### ansible-playbook [core 2.16.6] config file = /etc/ansible/ansible.cfg configured module search path = ['/home/paulo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3/dist-packages/ansible ansible collection location = /home/paulo/.ansible/collections:/usr/share/ansible/collections executable location = /usr/bin/ansible-playbook python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3) jinja version = 3.0.3 libyaml = True Using /etc/ansible/ansible.cfg as config file setting up inventory plugins Loading collection ansible.builtin from host_list declined parsing /home/paulo/learn-terraform-aws-instance/hosts.yml as it did not pass its verify_file() method script declined parsing /home/paulo/learn-terraform-aws-instance/hosts.yml as it did not pass its verify_file() method Not replacing invalid character(s) "{'-'}" in group name (tarraform-ansible) [WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details Not replacing invalid character(s) "{'-'}" in group name (tarraform-ansible) Parsed /home/paulo/learn-terraform-aws-instance/hosts.yml inventory source with ini plugin ERROR! conflicting action statements: copy, content

The error appears to be in '/home/paulo/learn-terraform-aws-instance/playbook.yml': line 3, column 5, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

tasks:

  • name: criando o arquivo ^ here

############################

Arquivo

  • hosts: terraform-ansible tasks:
    • name: criando o arquivo copy: dest: /home/ubuntu/index.html content:

      Feito com Terraform Ansible

    • name: criando o servidor shell: "nohup busybox httpd -f -p 8080 &"

      Obrigado.

2 respostas

Oii, Paulo, tudo bem?

No Ansible, quando você usa o módulo copy, você pode especificar o conteúdo diretamente com a chave content ou especificar um arquivo local para ser copiado com a chave src. No entanto, você não pode usar ambas as chaves na mesma tarefa.

Para o seu caso, você deve usar apenas a chave content junto com dest.

Seu YAML ficaria assim:

- hosts: terraform-ansible
  tasks:
  - name: criando o arquivo
    copy:
      dest: /home/ubuntu/index.html
      content: |
        <h1>Feito com Terraform Ansible</h1>

  - name: criando o servidor
    shell: "nohup busybox httpd -f -p 8080 &"

Adicionei um pipe | depois do content:. Isso indica um bloco de texto multi-linha no YAML, que é necessário para inserir o HTML certinho.

Se outra dúvida surgir, estamos aqui.

Abraços e bons estudos!

Caso este post tenha lhe ajudado, por favor, marcar como solucionado ✓.

Obrigado Maria! Resolvido!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software