Ask Your Question
1

How to use Hiera to create a MySQL users?

asked 2013-08-21 16:15:36 -0500

radeksimko gravatar image

If I use following module, how do I create new users & assign privileges to them via Hiera? https://github.com/example42/puppet-mysql/blob/master/manifests/grant.pp

I tried following:

"mysql::grant": [
    {
        "mysql_db": "mydb",
        "mysql_host": "localhost",
        "mysql_user": "radek",
        "mysql_password": ""
    },
    {
        "mysql_db": "mydb",
        "mysql_host": "%",
        "mysql_user": "radek",
        "mysql_password": ""
    },
    {
        "mysql_db": "mydb",
        "mysql_host": "localhost",
        "mysql_user": "john",
        "mysql_password": ""
    },
    {
        "mysql_db": "mydb",
        "mysql_host": "%",
        "mysql_user": "john",
        "mysql_password": ""
    }
]

But it doesn't seem to work, so I must be wrong in syntax.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-08-21 17:20:16 -0500

llowder gravatar image

If you use some yaml like the following, and use puppet 3 you can make use of databindings to do this.

module::class:mysql_user_list:
  - user1: 
    - mysql_db: "mydb",
    - mysql_host: "localhost",
    - mysql_user: "radek",
    - mysql_password: ""
  - user2:
    - mysql_db: "mydb",
    - mysql_host: "%",
    - mysql_user: "radek",
    - mysql_password: ""
  - user3:
    - mysql_db: "mydb",
    - mysql_host: "localhost",
    - mysql_user: "john",
    - mysql_password: ""
  - user4:
    - mysql_db: "mydb",
    - mysql_host: "%",
    - mysql_user: "john",
    - mysql_password: ""

If you use a class like:

class module::class (
  $mysql_user_list,
) {
  create_resources('mysql::grant', $mysql_user_list)
}

that will accomplish what you are trying to do.

If you don't have puppet 3, you just need to instead add an explicit hiera call, such as $mysql_user_list = hiera('module::class::mysql_user_list').

edit flag offensive delete link more

Comments

I have puppet 3.2.4, but it doesn't seem to work. No user is being created when using provided YAML. Anyway where this is documented ("mysql_user_list")?

radeksimko gravatar imageradeksimko ( 2013-08-22 02:09:11 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-08-21 16:15:36 -0500

Seen: 1,603 times

Last updated: Aug 21 '13