# How to create a puppet module with pdk using ansible?

**URL:** <https://forum.ansible.com/t/how-to-create-a-puppet-module-with-pdk-using-ansible/28036>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [July 12, 2018, 2:27pm UTC](https://forum.ansible.com/t/how-to-create-a-puppet-module-with-pdk-using-ansible/28036 "2018-07-12T14:27:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabio\_Gomes\_Sakiyama](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@Fabio\_Gomes\_Sakiyama](https://forum.ansible.com/u/Fabio_Gomes_Sakiyama)\
**Post date:** [July 12, 2018, 2:27pm UTC](https://forum.ansible.com/t/how-to-create-a-puppet-module-with-pdk-using-ansible/28036/1 "2018-07-12T14:27:49Z")

</div>

Hi,

I’m trying to create a new puppet module using pdk (pdk new module moduleName) with ansible, but this command requires some prompts and I’m struggling to make it work.

I tried the ansible [expect](https://docs.ansible.com/ansible/latest/modules/expect_module.html)module, but without success.

Here’s the command from shell:

```auto
[fabiosakiyama@puppetmaster modules]$ pdk new module conf
pdk (INFO): Creating new module: conf

We need to create the metadata.json file for this module, so we're going to ask you 4 questions.
If the question is not applicable to this module, accept the default option shown after each question. You can modify any answers at any time by manually updating the metadata.json file.

[Q 1/4] If you have a Puppet Forge username, add it here.
We can use this to upload your module to the Forge when it's complete.
--> fabiosakiyama

[Q 2/4] Who wrote this module?
This is used to credit the module's author.
--> fabiosakiyama

[Q 3/4] What license does this module code fall under?
This should be an identifier from https://spdx.org/licenses/. Common values are "Apache-2.0", "MIT", or "proprietary".
--> Apache-2.0

[Q 4/4] What operating systems does this module support?
Use the up and down keys to move between the choices, space to select and enter to continue.
--> RedHat based Linux, Debian based Linux, Windows

Metadata will be generated based on this information, continue? Yes

```

Here’s the playbook task:

```auto
- name: Create conf module
  expect:
    chdir: /etc/puppetlabs/code/environments/production/modules/
    command: /opt/puppetlabs/pdk/bin/pdk new module conf
    responses:
      .*: '\r'
      .*: '\r'
      .*: '\r'
      .*: '\r'
      .*: '\r'

```

```auto

```

```auto
I want to answer 'enter' to all answers, since there's a default answer. So i tried with '\r' and ' '.

```

```auto

```

```auto
Any help?

```

```auto

```

```auto
Thanks in advance!

```

---

<div class="post-metadata">

**Author:** ![Guilherme\_Costa](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@Guilherme\_Costa](https://forum.ansible.com/u/Guilherme_Costa)\
**Post date:** [July 12, 2018, 2:51pm UTC](https://forum.ansible.com/t/how-to-create-a-puppet-module-with-pdk-using-ansible/28036/2 "2018-07-12T14:51:15Z")

</div>

Hi,

I’m not sure about how to do what you want with the expect module, but if all you want to do is to create a new module with the default configurations, you can do so adding the --skip-interview flag to pdk new module (at least according to the documentation at [https://puppet.com/docs/pdk/1.x/pdk\_creating\_modules.html#concept-9353](https://puppet.com/docs/pdk/1.x/pdk_creating_modules.html#concept-9353), I personally haven’t tried it yet):

"Optionally, to omit the interview questions and create the module with default metadata values, add the `skip-interview` flag: `pdk new module <MODULE_NAME> --skip-interview"`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 12, 2018, 3:05pm UTC](https://forum.ansible.com/t/how-to-create-a-puppet-module-with-pdk-using-ansible/28036/3 "2018-07-12T15:05:45Z")

</div>

The question/prompt part of responses must be unique, if you have more than one response for a prompt you need to make them a list under the same prompt.

.\* doesn't give meaning in expect, "." is any character and "\*" is zero or more, so this will trigger a response way before any prompt is printed.

This should work since there are a little delay before expect write the response:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;responses:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'--\>':  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- ''  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue\?: ''

---

<div class="post-metadata">

**Author:** ![Fabio\_Gomes\_Sakiyama](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@Fabio\_Gomes\_Sakiyama](https://forum.ansible.com/u/Fabio_Gomes_Sakiyama)\
**Post date:** [July 12, 2018, 5:14pm UTC](https://forum.ansible.com/t/how-to-create-a-puppet-module-with-pdk-using-ansible/28036/4 "2018-07-12T17:14:52Z")

</div>

Hi Guilherme! Just tested and it worked! Thanks a lot!

But now I’m curious how to make it work without skipping the interview.

---

<div class="post-metadata">

**Author:** ![Fabio\_Gomes\_Sakiyama](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@Fabio\_Gomes\_Sakiyama](https://forum.ansible.com/u/Fabio_Gomes_Sakiyama)\
**Post date:** [July 12, 2018, 5:31pm UTC](https://forum.ansible.com/t/how-to-create-a-puppet-module-with-pdk-using-ansible/28036/5 "2018-07-12T17:31:55Z")

</div>

Hi Kai,

Thanks for clarifying!

Took some time to understand your answer, could you confirm if I’m correct?

When I write:

```auto
- name: Create conf module
  expect:
    chdir: /etc/puppetlabs/code/environments/production/modules/
    command: /opt/puppetlabs/pdk/bin/pdk new module conf
    responses:
      '-->':
        - " 
        - "
        - " 
        - "
      continue\?: "

```

```auto

```

```auto
I'm telling that I have 2 pattern for the questions:

```

```auto
- The questions that ends with -->

```

```auto
- The question that ends with 'continue?'

```

```auto
And the " means that the answer is just an enter. Is that correct?

```

`

Unfortunately, the code above didn’t work. The error is:

ERROR! Syntax Error while loading YAML.  
found unexpected end of stream

The error appears to have been in ‘/etc/ansible/roles/puppetserver/tasks/main.yml’: line 37, column 1, but may  
be elsewhere in the file depending on the exact syntax problem.

(specified line no longer in file, maybe it changed?)

`

```auto

When I deleted the last line ('continue\?'), it didn't fail because of the syntax, instead it failed because:

```

```auto

fatal: [puppetmaster]: FAILED! => {"changed": false, "msg": "No remaining responses for '-->', output was ' \u001b[36m(fabiosakiyama)\u001b[0m \u001b[2K\u001b[1G-->'"}

Based on that, it seems that he had the answers for the first 4 questions, but not for the last question. 

```

```auto

```

```auto
So I assumed I'm missing something on the syntax to code the last question/answer.

```

```auto

```

```auto
I tried as well like this and some other variations:

```

```auto
    responses:
      '-->':
        - " 
        - "
        - " 
        - "
      'continue?': "

```

```auto

```

```auto
Any clues?

```

```auto

```

```auto
Thanks in advance!

```

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 12, 2018, 5:45pm UTC](https://forum.ansible.com/t/how-to-create-a-puppet-module-with-pdk-using-ansible/28036/6 "2018-07-12T17:45:46Z")

</div>

> Hi Kai,
> 
> Thanks for clarifying!
> 
> Took some time to understand your answer, could you confirm if I'm correct?
> 
> When I write:
> 
> - name: Create conf module  
> &nbsp;&nbsp;expect:  
> &nbsp;&nbsp;&nbsp;&nbsp;chdir: /etc/puppetlabs/code/environments/production/modules/  
> &nbsp;&nbsp;&nbsp;&nbsp;command: /opt/puppetlabs/pdk/bin/pdk new module conf  
> &nbsp;&nbsp;&nbsp;&nbsp;responses:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'--\>':  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- "  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue\?: "
> 
> I'm telling that I have 2 pattern for the questions:
> 
> - The questions that ends with --\>
> 
> - The question that ends with 'continue?'

That is correct.  
The question mark is escaped since ? is a special character in regexp.

> And the " means that the answer is just an enter. Is that correct?

It should be two single quote or two double quotes, not one double quote as you have here.  
A empty string will be the same as just pressing enter key.

> Unfortunately, the code above didn't work. The error is:
> 
> ERROR! Syntax Error while loading YAML.  
> found unexpected end of stream
> 
> The error appears to have been in '/etc/ansible/roles/puppetserver/tasks/  
> main.yml': line 37, column 1, but may  
> be elsewhere in the file depending on the exact syntax problem.
> 
> (specified line no longer in file, maybe it changed?)
> 
> When I deleted the last line ('continue\?'), it didn't fail because of  
> the syntax, instead it failed because:
> 
> fatal: [puppetmaster]: FAILED! =\> {"changed": false, "msg": "No  
> remaining responses for '--\>', output was '  
> \u001b[36m(fabiosakiyama)\u001b[0m \u001b[2K\u001b[1G--\>'"}  
> Based on that, it seems that he had the answers for the first 4  
> questions, but not for the last question.
> 
> So I assumed I'm missing something on the syntax to code the last  
> question/answer.
> 
> I tried as well like this and some other variations:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;responses:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'--\>':  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- "  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'continue?': "
> 
> Any clues?

I think all of it is because of the missing quotes.
